jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

How to get keys from json object

Open thotanaresh opened this issue 7 years ago • 1 comments

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.

thotanaresh avatar Sep 25 '18 22:09 thotanaresh

This one worked for me: let itemKeys = jsonPath.paths(data, '$.*').map((res) => res[1]);

ratkorle avatar Feb 14 '19 09:02 ratkorle