# How To Use JSON.parse() and JSON.stringify()

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.

![text](https://media.licdn.com/dms/image/C4D22AQHX1gjywrtfFA/feedshare-shrink_2048_1536/0/1628406424867?e=1691625600&v=beta&t=QncasMtFQYHdW0Spw6YhVS_k8I_VQIDmkYNcRGCZGCs align="left")
