JysonCompliance

Version 2 (Alan Kennedy, 03/17/2009 09:15 pm)

1 1
h1. Compliance of jyson
2 1
3 2 Alan Kennedy
{{toc}}
4 2 Alan Kennedy
5 1
There are two main areas where jyson needs to be compliant.
6 1
7 1
h2. RFC 4627
8 1
9 1
JSON was originally specified with a simple syntax diagram on "JSON.org":http://json.org
10 1
11 1
As JSON became more and more widely used, an internet RFC was published by Douglas Crockford, the original creator of JSON. That document is "RFC 4627":http://www.ietf.org/rfc/rfc4627.txt , which is now the definitive specification for JSON.
12 1
13 1
I am currently conducting a review of jyson's compliance with RFC 4627.
14 1
15 1
h2. The cpython json module.
16 1
17 1
I originally wrote jyson back in 2005, and devised my own API.
18 1
19 1
Now, there is a "json module":http://docs.python.org/library/json.html in the cpython standard library, as of version 2.6. Which means that jython will need to have a json module when it reaches version 2.6. This may be achieved by running the pure python version of the json module (the cpython json module relies on C extensions for some of it's speed).
20 1
21 1
But the C extensions won't run on jython, meaning that jython will suffer a speed penalty running the existing pure python module.
22 1
23 1
If jyson can be made to implement the same API as the cpython json module, then I will contribute the module to jython.
24 1
25 1
Here is a list of the main areas in which there are differences between the APIs
26 1
27 2 Alan Kennedy
h3. Output to file-like objects
28 2 Alan Kennedy
29 2 Alan Kennedy
The "cpython json module":http://docs.python.org/library/json.html has facilities for the user to decode from and encode to file-like objects, as well as strings. 
30 2 Alan Kennedy
31 2 Alan Kennedy
Jyson only supports decoding from and encoding to strings: how those strings are transcoded for storage or rx/tx over a network is left to user.
32 2 Alan Kennedy
33 2 Alan Kennedy
h3. Character encodings
34 2 Alan Kennedy
35 2 Alan Kennedy
Because the "cpython json module":http://docs.python.org/library/json.html supports encoding and decoding from file-like objects, it has no choice but to concern itself with character encodings, since file-like objects are byte-oriented.
36 2 Alan Kennedy
37 2 Alan Kennedy
Jyson leaves the task of character encoding to the user. For example, the character encoding of a JSON document might be declared in a HTTP header, which is available to the programmer, but not to jyson.
38 2 Alan Kennedy
39 2 Alan Kennedy
When JSON was originally created, it contained no specifications for character encoding. However, "RFC 4627":http://www.ietf.org/rfc/rfc4627.txt now contains specifications of how JSON codecs should behave in relation to character encodings, and so jyson will have to the same.
40 2 Alan Kennedy
41 2 Alan Kennedy
h3. Incremental support
42 2 Alan Kennedy
43 2 Alan Kennedy
The "cpython json module":http://docs.python.org/library/json.html supports for generating JSON documents incrementally, i.e. in a series of smaller parts.
44 2 Alan Kennedy
45 2 Alan Kennedy
Jyson was originally written before jython supported generators, and this does not support this usage pattern.