« E4X: Predicate Filtering with Regular Expressions How to use FlexUnit with FlexBuilder 2 »

February 28, 2006

ActionScript 3 JSON Library Now Available

I'm happy to announce that my JSON library has been made publicly available through labs. JSON stands for "JavaScript Object Notation" and is a lightweight data exchange format, sort of like WDDX on a diet.

You can download the JSON library as part of the core ActionScript 3 library.

Usage is as follows:

// import the JSON library from the core serialization package
import com.macromedia.serialization.json.JSON;

// Encode a native ActionScript object as a JSON string
var jsonString:String = JSON.encode( someValue );

// Decode a JSON string into a native ActionScript object
var value:* = JSON.decode( jsonString ); 

If you run into any problems with it, let me know. It passed all of the unit tests, but there's always a chance that a test case is missing and there's a hidden bug somewhere. I'm interested in hearing any feedback you may have!

Tags: , , , , , ,

Comments

  • Here's the JSON test suite:

    http://labs.macromedia.com/svn/flashplatform/?/projects/corelib/trunk/src/actionscript3/com/macromedia/serialization/json/tests/JSONTest.as

    Numbers could use some more tests. What happens if you run 6.02e23 through an encode/decode? =)

  • Thanks Robert, I'll take a look at it and update the code in the repository as soon as I can find time to fix it.

  • The AS2 implementation has the same issue:

    http://www.theorganization.net/work/jos/JSON.as

  • No worries, it's just a simple tweak to readNumber() inside of the tokenizer:

    http://labs.macromedia.com/svn/flashplatform/?/projects/corelib/trunk/src/actionscript3/com/macromedia/serialization/json/JSONTokenizer.as

    I'm not checking correctly for exponents. I'll fix it tomorrow if I can squeeze in the time.

Post a comment

Remember personal info?