0

I wanna get children names of this JSON via JSONPath:

{
  "status": "success",
  "data": {
    "blaze": {
      "status": false
    },
    "fire": {
      "status": true
    },
    "thunder": {
      "status": false
    }
  }
}

and Output must be this:

["blaze", "fire", "thunder"]

but when i use data.*, i get incorrect and different response. I just want the correct parameter, because i'm using on several programming languages and i don't use the other referrences/functions.

Colduction
  • 103
  • 7

1 Answers1

1

Indeed data.* will return you the value of the objects inside the data object of your given array.
Your json -

{
  "status": "success",
  "data": {
    "blaze": {
      "status": false
    },
    "fire": {
      "status": true
    },
    "thunder": {
      "status": false
    }
  }
}

and the output of $.data.* expression -

[
  {
    "status": false
  },
  {
    "status": true
  },
  {
    "status": false
  }
]

To just access the keys of data object you have to use ~ operator.

Using the expression $.data.*~ you will get the output as -

[
  "blaze",
  "fire",
  "thunder"
]

Here you can test it. Credit to: This answer

Dev
  • 2,739
  • 2
  • 21
  • 34