Skip to main content
Question

JSON parser jsonpath regex


amugofjava
Apprentice
Forum|alt.badge.img

​Hi,

I am trying to search for a department using a custom field. This cannot be achieved using the department web service, so I am listing all departments and attempting to pull out the department I need via the JSON parser, but I am running into difficulties.

Given the following JSON payload:

{
    "departments": [
        {
            "description": "Department 1",
            "custom_fields": {
                "company_email_addresses": "dp1_support@mydomain.com,dp1_community@mydomain.com",
                "industry": "Transportation",
                "geography": null,
                "escalation_path": null,
                "account_active": true
            },
            "id": 1234567891,
            "name": "DP1",
            "created_at": "2024-02-29T09:14:52Z",
            "updated_at": "2024-02-29T09:14:52Z"
        },
        {
            "description": "Department 2",
            "custom_fields": {
                "company_email_addresses": "dp2_support@mydomain.com,dp2_community@mydomain.com",
                "industry": "Communications",
                "geography": null,
                "escalation_path": null,
                "account_active": true
            },
            "id": 1234567892,
            "name": "DP2",
            "created_at": "2024-02-29T09:14:52Z",
            "updated_at": "2024-02-29T09:14:52Z"
        }
    ]
}

I am trying to pull out name where the company_email_addresses field contains a string:

$.departments[?(@.custom_fields.company_email_addresses =~ /.*dp1_support@mydomain.com.*/i)].name

What I am finding is, that both departments from the data are returned; it’s not matching:


If I do a direct == match, it works perfectly, but I cannot get it to work with a regular expression.

There do seem to be a number of variations on the jsonpath syntax.

Does anyone know what style FS is using and the correct way to pattern match?

Thanks.

Did this topic help you find an answer to your question?

0 replies

Join the Community or User Group to Participate in this Discussion

Reply