3

I was trying to find a way to convert the json array to json string.

http://jsonpath.com/

JSON

{
  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  },
  "phoneNumbers": [
    {
      "type"  : ["iPhone"],
      "number": "0123-4567-8888"
    },
    {
      "type"  : ["home"],
      "number": "0123-4567-8910"
    }
  ]
}

Output iphone

Expression I tried,

$.phoneNumbers[:1].type[,]
$.phoneNumbers[:1].type
$.phoneNumbers[:1].type

Thanks in advance

dbc
  • 104,963
  • 20
  • 228
  • 340
devanathan
  • 768
  • 3
  • 10
  • 39
  • 3
    What's the question/problem? Do you get the wrong output? Btw, why is `type` an array in the first place? Can't a number just have one type (it seems to be more of a label anyways)? – Thomas Mar 31 '17 at 13:35
  • Try `$.phoneNumbers[:1].type[*]` to get an array of types of the first phone number. Reference: http://goessner.net/articles/JsonPath/index.html#e3 – Luciano van der Veekens Mar 31 '17 at 14:53

0 Answers0