The JSON object, available in all modern browsers, has two useful methods to deal with JSON-formatted content: ๐ฉ๐๐ซ๐ฌ๐ ๐๐ง๐ ๐ฌ๐ญ๐ซ๐ข๐ง๐ ๐ข๐๐ฒ.
๐น ๐๐๐๐.๐ฉ๐๐ซ๐ฌ๐() takes a JSON string and transforms it into a JavaScript object.
๐น ๐๐๐๐.๐ฌ๐ญ๐ซ๐ข๐ง๐ ๐ข๐๐ฒ() takes a JavaScript object and transforms it into a JSON string.
โ ๐จ๐ ๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐ โ
โ๏ธ ๐๐๐๐.๐ฉ๐๐ซ๐ฌ๐()
It can take a ๐๐ฎ๐ง๐๐ญ๐ข๐จ๐ง ๐๐ฌ ๐ ๐ฌ๐๐๐จ๐ง๐ ๐ฉ๐๐ซ๐๐ฆ๐๐ญ๐๐ซ
that can transform the object values before they are returned.
In the example below the objectโs values are transformed to uppercase in the returned object of the parse method.
โ๏ธ ๐๐๐๐.๐ฌ๐ญ๐ซ๐ข๐ง๐ ๐ข๐๐ฒ()
It can take ๐ญ๐ฐ๐จ ๐๐๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ parametes:
the first one being a ๐ซ๐๐ฉ๐ฅ๐๐๐๐ซ function,
and the second ๐ ๐๐ญ๐ซ๐ข๐ง๐ ๐จ๐ซ ๐๐ฎ๐ฆ๐๐๐ซ value to use as a ๐ฌ๐ฉ๐๐๐ in the returned string.
๐๐ก๐ ๐ซ๐๐ฉ๐ฅ๐๐๐๐ซ function can be used to filter out values, as any value returned as undefined will be out of the returned string.
๐๐ก๐ ๐ฌ๐ฉ๐๐๐ argument is used to insert white space into the output JSON string for readability purposes.