3 ms·
I like dealing with data that's line-denormalized like this since it's a lot easier to manipulate with simple things like grep and awk. If you do too, and you
by philsnow 8y ago
I like dealing with data that's line-denormalized like this since it's a lot easier to manipulate with simple things like grep and awk.
If you do too, and you find yourself dealing with JSON a lot, take a look at gron [0], it takes JSON and denormalizes all the structure into a line-oriented equivalent.
% echo '{"root": {"left": [1, 1.4, 2, 2.88], "right": ["a", "b"]}}' | jq .
{
"root": {
"left": [
1,
1.4,
2,
2.88
],
"right": [
"a",
"b"
]
}
}
% echo '{"root": {"left": [1, 1.4, 2, 2.88], "right": ["a", "b"]}}' | gron
json = {};
json.root = {};
json.root.left = [];
json.root.left[0] = 1;
json.root.left[1] = 1.4;
json.root.left[2] = 2;
json.root.left[3] = 2.88;
json.root.right = [];
json.root.right[0] = "a";
json.root.right[1] = "b";
[0] https://github.com/tomnomnom/gron https://github.com/tomnomnom/gron
- thechao 8y agoAHHA! My brother in arms! I also have a gron-like ML called 'KVIN'[0]. It'd be like this: root.left[0] = 1 .left[1] = 1.4 .left[2] = 2 root.left[3] = 2.88 ..right[0] = "a" .right[1] = "b" [0] https://github.com/jaroslov/kvin https://github.com/jaroslov/kvin
- aasasd 8y agoEurgh, you've just put another blemish on this world's karma with that sad affair of manipulating structured data as indiscriminate mess of letters. If keys in your input contain dots, what will grep and awk do to help you out? Meanwhile, the JQ tool could do your greppings and awkings but preserving and perusing the structure of the document notwithstanding its idiosyncrasies. (A possible problem with JQ, though, is that it may be difficult to query a structure which varies, i.e. use entries on a nesting level that isn't known in advance.)
- anyfoo 8y ago> If keys in your input contain dots, what will grep and awk do to help you out? Without knowing gron, I presume the dots are escaped/quoted properly, and you would do the same in your grep/awk usage. What if your keys contain equal signs and curly braces, how will json help you out? > Meanwhile, the JQ tool could do your greppings and awkings but preserving and perusing the structure of the document notwithstanding its idiosyncrasies. The structure of the data is preserved (I don't know what you mean with "notwithstanding its idiosyncrasies"). This is just a different, albeit redundant, but entirely equivalent representation of the same document. Despite their redundancy, denormalized representations do have advantages.
- aasasd 8y ago> I presume the dots are escaped/quoted properly, and you would do the same in your grep/awk usage. Oh yeah, that's certainly much easier than having a tool's parser deal with the syntax, and just working with individual keys and values instead. So much so that in fifteen years of programming I haven't seen anyone remember to include escape-sequences in their regexps. But I guess for true lovers of regexps it's just a joy to keep escaping the escape sequences that they put in, and then escaping the result once over in the coding language of choice. > What if your keys contain equal signs and curly braces, how will json help you out? Care to clarify why that would be a problem?