Shukri Adams
Shukri Adams

Reputation: 941

Select attribute name with JsonPath

I'm consuming a JSON feed that returns a structure with an array of irregular objects - I can't predict what's in the array, and whatever is there will change over time. A simple example is

{
 "content":
   [
     {
       "person"  : "john"
     },
     {
       "car"  : "Audi"
     }
   ]
 }

The JsonPath query

$.content.[0]

returns the first object in that array. But, I need a jsonpath query that returns the literal NAME of the first property of that object, in this case I need the query to return "person". Is this possible?

Upvotes: 14

Views: 2705

Answers (1)

Bhaskar13
Bhaskar13

Reputation: 371

$.content.[0].*~

Tested on JSON path

Upvotes: 6

Related Questions