Converting JSON objects to string


anyObj=[{"test1":1, "test2":2}];

// from JS object to a JSON String
jsonString = XSP.toJson(anyObj);

// from JSON String to a JS object
jsonObj = XSP.fromJson(jsonString);

// jsonString : "[{"test1":1,"test2":2}]"
// jsonObject: [Object { test1=1,  test2=2}]

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
2 comment(s)Login first to comment...
Serdar Basegmez
(at 06:33 on 27.08.2016)
Done! Thank you.
Hunter Medney
(at 10:58 on 16.04.2015)
Hi, please consider updating the snippet...the current CSJS methods for object<->json conversion are:
XSP.toJson(object)
XSP.fromJson(strJson)