3 ms·
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
by whalesalad 14y ago
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"]
],
- ZenPsycho 14y agoif 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 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.
- dogada 14y agoExactly, 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.
- danieldk 14y agoDoesn't this introduce ambiguity? How do you represent list of 'tuple lists'?
- ZenPsycho 14y agoyou could steal the method rjson uses and do this "users": [ [3, "first", "last"], [3, "Homer", "Simpson"], [3, "Hank", "Hill"], [3, "Peter", "Griffin"] ],
- dogada 14y agoYou can see it in the unit tests: https://github.com/dogada/RJSON/blob/master/test/tests.js#L43 https://github.com/dogada/RJSON/blob/master/test/tests.js#L4...
- snorkel 14y agoPrefer this approach. It's more readable and less fragile.