#1 2020-07-27 19:51:54

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 32

Json Path

Hello,

How to get the second phoneNumbers type element using path (phoneNumbers[1].type) giving home

{
  "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"
    }
  ]
}

Best regards.

Offline

#2 2020-07-28 09:21:02

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Json Path

Offline

#3 2020-07-28 12:42:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Json Path

Yes, https://synopse.info/forum/viewtopic.ph … 243#p31243 is a simple alternative too.

If you want something fast, you can also use a record with a nested dynamic array.
It is faster than TDocVariant, and more native to access the members, but a little more code to write to setup the serialization.

Online

#4 2020-07-28 13:35:29

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Json Path

I think his question is how to get the value directly without looping the properties. Something like an xpath ....

If so, I believe that GetValueByPath does not have this functionality.

But take a look at the documentation on methods like GetItemByProp, GetDocVariantByProp, SearchItemByProp

Offline

Board footer

Powered by FluxBB