JSON must always have double quoted string keys, so examples like these are invalid:
{ fileName: "XYZ" }
{ 'fileName': "XYZ" }
However, this is a valid JSON format:
{ "fileName": "XYZ" }
Javascript objects do not require key quoting, but if used, single quotes can be used as well:
let a = { fileName: "XYZ" };
let b = { 'fileName': "XYZ" };
let c = { "fileName": "XYZ" };
Here, a
, b
, and c
are all equivalent.
Regardless of the key formatting, iterating through JavaScript objects is done in the same manner:
for (let key in a) {
console.log(`${ key }: ${ a[key] }`);
}
Object.keys(b).forEach(key => console.log(`${ key }: ${ b[key] }`));