KD_stack
KD_stack

Reputation: 161

Multiple filters in JSONPath

I am trying to extract data using JSONPath, and using multiple filters.

In the JSON below, some have 'program.seriesId', and some don't. I want to extract the first 'value' that has no 'program.seriesId'

When I put the JSONPath below in the JSON evaluator http://jsonpath.com/:

$.data[?(@.program.seriesId)].value

I get 123 AND 345. However I only want the first 'value' of 123.

I've tried the following multiple filter JSONPaths, but all return no matches:

$.data[?(@.program.seriesId)][0].value
$.data[?(@.program.seriesId) && 0].value
$.data[?(@.program.seriesId) and 0].value

What is the JSONPath query to return the first 'value' , that has no 'program.seriesId'?

{
    "data": [
    {
        "value": "123",
        "program": {
            "id": "011",
            "seriesId": "111"
        }
    },
    {
        "value": "234",
        "program": {
            "id": "022"
        }
    },
    {
        "value": "345",
        "program": {
            "id": "033",
            "seriesId": "333"
        }
    }]
}

Upvotes: 4

Views: 5700

Answers (1)

Helping hand
Helping hand

Reputation: 2930

I was also searching for printing 1st result object from the array of objects when I came across this question.

I found out that currently it is not possible to get index based result. Github Open issue link , which is open since more than an year.

Otherwise it could have been something like this,

$.data[?(@.program.seriesId)][0].value

Upvotes: 1

Related Questions