News for hackers. Stuff that matters.
Re:RJSON: compress JSON to JSON by ZenPsycho on Tuesday June 05, 2012 @09:07AM (#4068454)
I see a pretty major problem with this. It seems to depend on the order of key value pairs in object literals being defined. The order is not defined by the JSON or the ecmascript standards. So you can't really depend on the order of keys in a json object, unless you explicitly define some order (like alphabetical, for instance). I like the basic concept of compressing json to json but this is not a particularly good way to do it- since the order of those keys may not be preserved in round trips through json encoders and decoders in various languages.
Re:RJSON: compress JSON to JSON by whalesalad on Tuesday June 05, 2012 @09:26AM (#4068527)
I saw the same thing right away. Seems like the first item in the array would have to be used as a hash of key/index pairs to be used for the following items. I guess this would only be useful with large sets of data, the examples makes them look kind of silly =)

So this:

    "users": [
        {"first": "Homer", "last": "Simpson"},
        {"first": "Hank", "last": "Hill"},
        {"first": "Peter", "last": "Griffin"}
    ],
Becomes:

    "users": [
        ["first", "last"],
        ["Homer", "Simpson"],
        ["Hank", "Hill"],
        ["Peter", "Griffin"]
    ],
Re:RJSON: compress JSON to JSON by ZenPsycho on Tuesday June 05, 2012 @09:35AM (#4068549)
if you can infer a schema, I'd almost prefer a column oriented arrangement.

   "users": 
        {
         "first":["Homer","Hank","Peter"], 
         "last":["Simpson","Hill","Griffin"]
         },
then the information about the original structure can be restored by a set of object paths which need to be "rotated" from column to row orientation. ["users"]

saving a few characters in the process. though I see that the advantage of this system is supposedly that it can handle any sort of shape of data, not just ones with a fixed schema. I've been trying to figure out how trang [http://www.thaiopensource.com/relaxng/trang.html] does its schema inference trick. (it turns a set of xml files into a relaxNG schema). If you have a schema for a JSON file, it's knowledge you can apply to algorithmically creating really efficient transformations.

Re:RJSON: compress JSON to JSON by dogada on Tuesday June 05, 2012 @10:30AM (#4068755)
Exactly, ZenPsycho, the purpose of RJSON is to convert data with dynamic schema. Fields with default values are omitted often, for example if most of data have 'private' property set to False, it have sense to output it only for 1% of objects with 'private' set to True. This issue is addressed in RJSON.
Re:RJSON: compress JSON to JSON by snorkel on Tuesday June 05, 2012 @10:30AM (#4068752)
Prefer this approach. It's more readable and less fragile.
Re:RJSON: compress JSON to JSON by danieldk on Tuesday June 05, 2012 @09:42AM (#4068568)
Doesn't this introduce ambiguity? How do you represent list of 'tuple lists'?
Re:RJSON: compress JSON to JSON by dogada on Tuesday June 05, 2012 @10:32AM (#4068762)
Re:RJSON: compress JSON to JSON by ZenPsycho on Tuesday June 05, 2012 @09:46AM (#4068585)
you could steal the method rjson uses and do this

   "users": [
        [3, "first", "last"],
        [3, "Homer", "Simpson"],
        [3, "Hank", "Hill"],
        [3, "Peter", "Griffin"]
    ],
[deleted]
Re:RJSON: compress JSON to JSON by ZenPsycho on Tuesday June 05, 2012 @09:19AM (#4068505)
that is only enough to make it seem like it works okay. But as I said, there's nothing in the JSON spec that obligates any intervening party to preserve the order of the keys in the object.
Re:RJSON: compress JSON to JSON by dogada on Tuesday June 05, 2012 @12:37PM (#4069363)
It doesn't matter. Even if order of keys will be changed somewhere in the middle during JSON.strigify, as schema id will be always used keys sorted alphabetically and object values are always stored in the same order as keys sorted: https://github.com/dogada/RJSON/blob/master/rjson.js#L213
Re:RJSON: compress JSON to JSON by dogada on Tuesday June 05, 2012 @12:12PM (#4069229)
Thanks ZenPsycho, I added sorting of object schema keys to fix this issue: https://github.com/dogada/RJSON/commit/a27c8927cd0c2d7d151e2...