I have a given exif of an image I would like to split each key of a json object and create a sorted array with it. The output I'm expecting is
{
"APP14":[
{"APP14Flags0": 16384},
{"APP14Flags1": 0},
{"ColorTransform": 1}
],
"Composite":[
{"Aperture": 2.8}
{"CircleOfConfusion": 0.0309526315549036}
{"DateTimeCreated": "2013:08:04 13:15:03+00:00"}
{"FocalLength35efl": 97.0717484087605}
{"..."}
],
"SourceFile": "c.jpg",
"XMP":[
{"AlreadyApplied": true},
{"ApproximateFocusDistance": 1.17},
{"AutoLateralCA": 0},
{"Blacks2012": 0}
]
}
My last console.log({key:values}); is giving me back the same array. js fiddle
var the_keys =[];
_.forEach(data, function(n, key) {
//creating an array of Uniq keys
if(key.indexOf(':')> -1) {
if (_.includes(the_keys, key.split(':')[0] ) == false) {
the_keys.push(key.split(':')[0]);
}
} else {
the_keys.push(key);
}
});
console.log(the_keys);
_.forEach(the_keys, function(key) {
var values = []
_.forEach(data, function(k, n) {
if ((_.includes(the_keys, key.split(':')[0] ) ) || k == key) {
values.push(k);
}
});
console.log({key:values});
});
I'm splitting each keys cause I would like to create an HTML table like for this exif viewer site
{ "APP14":[ {"APP14Flags0": 16384}, {"APP14Flags1": 0}, {"ColorTransform": 1} ],