jsonpath
jsonpath copied to clipboard
How to get keys from json object
How can I get keys from a json object
let data = {
"key1": "value1",
"key2": "value2",
"key3": "value3",
"key4": {
"key5": "value5"
}
}
jp.query(data, '$.*~');
result:
Error: Lexical error on line 1. Unrecognized text.
However, I get expected output when I try on jsonpath.com
Please advise.
This one worked for me:
let itemKeys = jsonPath.paths(data, '$.*').map((res) => res[1]);