Viktor Carlson
Viktor Carlson

Reputation: 1008

JSON JsonPath -> get Array Value that contains String

Hi I have a JSON Object:

{      
    "idContainer": 
    [
        "213=135864",
        "312=35947"
    ]
}

Now I want to access the string 135864 that is after 213= (213 is a kind of key inside of the array value, I get the data formatted like this)

1.) I am trying to find a filter expression like this idContainer[?('213=*')] which returns me this element "213=135864"

2.) More convenient would be if I could filter the result even more and just return 135864 but I don't know if this is possible with JSON XPath Syntax

Thanks for help :)

If necessary I could also use Java expressions, but my favorite Solution would be pure JsonPath

Upvotes: 1

Views: 3765

Answers (1)

Daniel
Daniel

Reputation: 753

If you're using Jayway JSONPath, and if you're working in JAVA you probably are, you can use regular expressions in a filter condition, viz.

$.idContainer[?(@ =~ /213=.*/)]

That produces

[
   "213=135864"
]

But there's no way using Jayway to produce

[
    135864
]

Upvotes: 1

Related Questions