Recently, a particular user searched in vain for a fast, simple way to convert JSON text into AHK objects on the fly. The idea piqued my interest, so I wrote this library (packaged as separate functions, so as not to interfere with any other "JSON" library you might have).
The linked zip file contains two .ahk files which you may copy to the Lib folder of your choice or directly into your scripts. Kindly observe the included license.txt.
AHK-Lib-JSON.zip
I have not extensively tested these functions, so let me know if you find any bugs. The "stringify" function's output does NOT conform to the JSON specification (www.json.org), see readme.txt. Also, that function may rearrange the order of a non-array object's members.
Enjoy!

[Func] Convert Objects to/from JSON-like Strings
Started by
VxE
, Aug 11 2013 11:58 PM
3 replies to this topic
#1
-
Posted 11 August 2013 - 11:58 PM
![[Func] Convert Objects to/from JSON-like Strings: post #1](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Thanks for this VxE.
It will also help me port it to other languages.
#2
-
Posted 26 August 2013 - 08:40 PM
![[Func] Convert Objects to/from JSON-like Strings: post #2](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
don't duplicate, iterate!
TLM, you're welcome! Just out of curiosity, which other languages don't already have JSON deserializing (either built-in or as a public library)?
My deserializer differs from similar functions in that it does not invoke javascript, it does not use regex, it does not use recursion, and it does not call other user-defined functions.
These differences translate to speed. My tests show that JSON_ToObj (my function) is more than twice as fast as LSON_Deserialize (link in nimda's post above).
My deserializer differs from similar functions in that it does not invoke javascript, it does not use regex, it does not use recursion, and it does not call other user-defined functions.
These differences translate to speed. My tests show that JSON_ToObj (my function) is more than twice as fast as LSON_Deserialize (link in nimda's post above).
#4
-
Posted 27 August 2013 - 04:39 AM
![[Func] Convert Objects to/from JSON-like Strings: post #4](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)