JavaScript

How to decode a JSON string using JavaScript

Written by Ian Carnaghan · 13 sec read >

If you have a JSON encoded string that you might have received from a ajax scriptand you need to decode it using JavaScript you can use the eval() function to decode the string. The eval() function evaluates or executes an given argument.

Example:

var string = '{"id" : 32}'; 
var d = eval('(' + string + ')'); 
alert(d.id); //will alert 32

Last Updated On March 20, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of