Extract All Json Key From Unknown Json Structure
I'm a problem with an algorithm, I want know all key(nested object, array of object) from some json (unknown structures) file in one array. { 'key': 'value to array', 'key': [{
Solution 1:
Use Object.keys
var obj = {
key1: 'foo',
key2: 'bar'
};
var keys = Object.keys(obj);
//keys === ['key1', 'key2'];
Solution 2:
Just use Object.keys
and recursive functions.
functionallKeys(object) {
returnObject.keys(object).reduce((keys, key) =>
keys.concat(key,
typeofobject[key] === 'object' ? allKeys(object[key]) : []
),
[]
);
}
Post a Comment for "Extract All Json Key From Unknown Json Structure"