Was looking for it for quite some time. Finally decided to write it myself. JSON is a really cool thing  to use for data transfer of a complex objects. Here is how u transfer array or object in Javascript.To create a stringified value of an object is very simple:

if(typeof my_object == 'object')
  var stringified = JSON.stringify(my_object);

Now lets check if our string is actually a valid JSON:

if(!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(stringified.replace(/"(\\.|[^"\\])*"/g,''))))
  alert('I am JSON!');

Dima Svirid

Software architect, JAVA, Spring, Hibernate, AngularJs, Backbone, MongoDB, Oracle. CTO and Co-Founder of Homeadnet.com

More Posts

Follow Me:

Tagged with: