Hello all,
I wanted to make a quick post about Alpha's Implementation of JSON, mainly, it <del>is</del> was incorrect. I had been working on integrating Google Calendar into my Alpha application. It was going pretty good until I started working on the Google API integration. The latest version of the Google API (v3 for Calendar) accepts and returns JSON. I had many many problems working with the JSON functions in Alpha. They would not work on the data that I would get back from Google. Then when I would create a pointer structure and use varToJSON to send data back to Google, they would not accept it because it was malformed JSON.
Because of this, I did some research and came to the conclusion that Alpha has implemented JSON incorrectly. According to json.org, as well as the IETF RFC 4627, the names of the variables should be enclosed in quotes (from all their examples, it's double quotes). Alpha does not enclose the names of the variables in quotes at all, which makes it more akin to a javascript object, echo'd out as a string, instead of JSON. (There is a distinctive difference). That is the largest error, but there are others, such as a5_json_prep function stripping out null values, when the JSON spec specifically states that null is a valid value. I have submitted some bug reports for the JSON functions in Alpha, but have not heard anything back related to those (it's been a few months). Realizing that Alpha wasn't going to change these functions any time soon, I was forced to use PHP as an intermediary between Google and my Alpha application. (Which has been working great).
Anyways, the reason I'm writing a post about it today is because in the latest pre-release version, the changelog has information on some new JSON functions. And it looks like they're working correctly! (Although the example they give is incorrect, can't win 'em all)
Note: The vartojson function returns malformed JSON, but the (undocumented?) vartojsonstandard function returns correct! JSON. Success!!
The first example from json.org also seems to work right off the bat!
So, in conclusion, this post started out as a rant when I saw the changes in the changelog.
But, half way through the post I installed the beta, and tested the functions and the post turned into a success!
So thank you Selwyn and co. for fixing the issues I've had with the JSON implementation, but here's to hoping you deprecate and remove the incorrect functions (or at least name them javascript object instead of JSON)
I will soon be converting all my php back into xbasic so I can, once again, have a 100% Alpha app.
PS: It would be amazing if the examples, both in the changelog and the wiki, could be corrected to not discourage and confuse future developers.
EDIT: PPS: The null value bug has been fixed in the next build!
References:
www.json.org
http://www.ietf.org/rfc/rfc4627.txt?number=4627
Thanks for listening!
I wanted to make a quick post about Alpha's Implementation of JSON, mainly, it <del>is</del> was incorrect. I had been working on integrating Google Calendar into my Alpha application. It was going pretty good until I started working on the Google API integration. The latest version of the Google API (v3 for Calendar) accepts and returns JSON. I had many many problems working with the JSON functions in Alpha. They would not work on the data that I would get back from Google. Then when I would create a pointer structure and use varToJSON to send data back to Google, they would not accept it because it was malformed JSON.
Because of this, I did some research and came to the conclusion that Alpha has implemented JSON incorrectly. According to json.org, as well as the IETF RFC 4627, the names of the variables should be enclosed in quotes (from all their examples, it's double quotes). Alpha does not enclose the names of the variables in quotes at all, which makes it more akin to a javascript object, echo'd out as a string, instead of JSON. (There is a distinctive difference). That is the largest error, but there are others, such as a5_json_prep function stripping out null values, when the JSON spec specifically states that null is a valid value. I have submitted some bug reports for the JSON functions in Alpha, but have not heard anything back related to those (it's been a few months). Realizing that Alpha wasn't going to change these functions any time soon, I was forced to use PHP as an intermediary between Google and my Alpha application. (Which has been working great).
Anyways, the reason I'm writing a post about it today is because in the latest pre-release version, the changelog has information on some new JSON functions. And it looks like they're working correctly! (Although the example they give is incorrect, can't win 'em all)
Code:
dim text as c text = "{\"name\": \"John Smith\", \"married\": true, \"age\": 35, \"nul\": null }" ?text = {"name": "John Smith", "married": true, "age": 35, "nul": null } dim p as p p = INET::JSONParser::parse(text) ?p.name = "John Smith" ?p.married = .T. ?p.age = 35 ?p.nul = <No data returned> ?vartojson(p) = { name: 'John Smith', married: true, age: 35 } ?vartojsonstandard(p) ERROR: Variable type mismatch: attempt to pass data of type 'V' to argument 'var ' is of type 'C'. 'After removing the null ?vartojsonstandard(p) = { "name": "John Smith", "married": true, "age": 35 }
The first example from json.org also seems to work right off the bat!
Code:
dim text2 as c = "{\"glossary\": {\"title\": \"example glossary\",\"GlossDiv\": {\"title\": \"S\",\"GlossList\": {\"GlossEntry\": {\"ID\": \"SGML\",\"SortAs\": \"SGML\",\"GlossTerm\": \"Standard Generalized Markup Language\",\"Acronym\":\"SGML\", \"Abbrev\": \"ISO 8879:1986\",\"GlossDef\": {\"para\":\"A meta-markup language, used to create markup languages such as DocBook.\",\"GlossSeeAlso\": [\"GML\", \"XML\"]},\"GlossSee\": \"markup\"} } } }}"
But, half way through the post I installed the beta, and tested the functions and the post turned into a success!
So thank you Selwyn and co. for fixing the issues I've had with the JSON implementation, but here's to hoping you deprecate and remove the incorrect functions (or at least name them javascript object instead of JSON)
I will soon be converting all my php back into xbasic so I can, once again, have a 100% Alpha app.
PS: It would be amazing if the examples, both in the changelog and the wiki, could be corrected to not discourage and confuse future developers.
EDIT: PPS: The null value bug has been fixed in the next build!
References:
www.json.org
http://www.ietf.org/rfc/rfc4627.txt?number=4627
Thanks for listening!
Comment