Is it possible to get list of attributes of a particular JSON map with a JSONPath expression? For example:
{"foo": 1, "bar": 2}
=> ["foo","bar"]
Is it possible to get list of attributes of a particular JSON map with a JSONPath expression? For example:
{"foo": 1, "bar": 2}
=> ["foo","bar"]
You can use the following code:
Object.getOwnPropertyNames({"foo": 1, "bar": 2})
Here's a link for further information.
Loop through each json object get all the keys and push then into an array. You can try this:
var data=[{"foo": 1, "bar": 2},{"foo1": 1, "bar1": 2}];
var array=[];
$.each(data, function(key, value){
var item;
item=Object.keys(value);
array.push(item);
});
console.log(array);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>