12

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?

Shukri Adams
  • 851
  • 1
  • 12
  • 30

1 Answers1

5

$.content.[0].*~

Tested on JSON path

Bhaskar13
  • 191
  • 4
  • 14
  • Please accept this additional "+1" for answering my question after 8 long years. – Shukri Adams Feb 03 '22 at 21:14
  • Please note that ~ works only with some implementations of jsonpath and is not part of the original [spec](https://goessner.net/articles/JsonPath/index.html). https://jsonpath.com/ use the library [JSONPath plus](https://jsonpath-plus.github.io/JSONPath/docs/ts/#jsonpath-plus-) – Akshay G Feb 05 '22 at 10:29