1

I would like to retrieve only the first name ocurrence.

[
  {
    "name": "xx",
    "lastname": "yy",
    "child": [
      {
        "name": "x2"
      },
      {
        "name": "x3"
      }
    ]
  },
  {
    "name": "yy",
    "lastname": "xz"}
]

with this regex: $..name the result is:

[
  "xx",
  "x2",
  "x3",
  "yy"
]

and with this $..name[0] is:

[
  "x",
  "x",
  "x",
  "y"
]

but I'm looking for this result:

[
  "xx"
]

Note: it have to be in only one regex, I can't store result to after manipulate it

2
  • Have a look at jsonpath.herokuapp.com, you'll see that $..name[0] works for the Nebhale implementation. Based on the results you showed I suspect you are using Goessner's implementation. It might help to update the question to make this clear. Commented Dec 1, 2017 at 9:45
  • I was trying in http://jsonpath.com/, you site looks more complete. but that expression doesn't work for my implementation Gatling Commented Dec 1, 2017 at 10:00

1 Answer 1

2

$[0].name

will give you the first match only:

[  
   "xx"
]
Sign up to request clarification or add additional context in comments.

1 Comment

Go through how to write a correct answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.