Jason stringify

Topics: Developer Forum
Developer
Oct 22, 2013 at 5:33 PM
I was wondering if I am following the correct method for sending Json object to the browser.

Say, I want to return a simple JSON as follows to the browser
cJSON = [{"error":false, "msg":"Thank you.."}]
In this case my REST controller does the following ( this is the simplified version)
oRawJSON = CREATEOBJECT('empty')
ADDPROPERTY(oRawJSON,"error",.F.)
ADDPROPERTY(oRawJSON,"msg","Thank You.")
oJSON=NEWOBJECT('json',substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'prg\'+'json.prg') 
cJSON =  oJSON.stringify(oRawJSON)
oRawJSON = null
Return cJSON
Does anyone know if we can create Json without using CreateObject()?
Coordinator
Oct 27, 2013 at 8:59 AM
Edited Oct 27, 2013 at 8:59 AM
There's probably many different ways worth experimenting with.

In some of Victor's code he just does (and he created this project: https://qdfoxjson.codeplex.com/):
 *quick and dirty JSON
   cJSON = [{"custId":"] + RTRIM(custId) + [","custName":"] + RTRIM(custName) + [",] + ;
           ["custStat":"] + RTRIM(custStat) + ["}]
   RETURN cJSON 
Although, I think the header needs to be formatted correctly for proper JSON.

And any JSON you produce should always pass the test here: http://jsonlint.com/
Developer
Oct 28, 2013 at 2:59 AM
Thanks claude. I did not know of that site.