Monday, March 23, 2009

JSON plugin for jQuery

Version 1.0


Quickly convert JavaScript objects to JSON strings and back to objects.

Encode


var obj = {};
obj.name = "Test JSON";
obj.type = "test";
$.json.encode(obj); //output: {"name":"Test JSON", "type":"test"}


Decode


$.json.decode({"name":"Test JSON", "type":"test"}); //output: object


Download it here.

7 comments:

Anonymous said...

I think I maybe missing something. Whenever I try to run this I get

"text/replace is not a function" on line 100.

Any ideas?

Giraldo Rosales said...

Can you post (or email me) an example of what you are trying to do?

Thanks
-G

Anonymous said...

The problem seems to have cleared up. I discovered I was having some library conflicts. Once I resolved the conflicts, this problem went away.

Thanks for a great plugin!

Savraj said...

This is exactly what I was looking for -- excellent. I'm using 'serialize' to pretty print my json objects. It would be great to add line breaks and such so I can print to a web site.

Anonymous said...

Great plugin Giraldo!

Thanks pal!

To increase your popularity, I suggest you to add (or ask us) what version of jquery are tested (e.g. 1.0.x, 1.2.x, 1.3.1).

For example, even the version 1.3.2 is released, I cannot upgrade due to possible incompatibilities of the plugins.

Regards

AsGoodAsItGets said...

This doesn't seem to work with UTF-8 strings. I have problems encoding and decoding Greek characters.

Anonymous said...

you save my life dude !!
great thanks