←back to thread

115 points graderjs | 9 comments | | HN request time: 3.309s | source | bottom
1. andreareina ◴[] No.25005050[source]
Could use an example of the database file and diffs.

I have vague recollections of a tool that was similarly supposed to make JSON files diffable. IIRC it procedurally built up the object, so {"foo": {"bar": "baz", "quux": [1, 2, 3]}} would be:

    foo = {}
    foo.bar = "baz"
    foo.baz = []
    foo.baz[0] = 1
    ...
replies(3): >>25005118 #>>25005451 #>>25005522 #
2. PowerfulWizard ◴[] No.25005118[source]
This is called gron, I prefer it for reading JSON with a lot of nesting.

https://github.com/tomnomnom/gron

replies(2): >>25005274 #>>25005506 #
3. robador ◴[] No.25005274[source]
This is amazing!
4. graderjs ◴[] No.25005451[source]
The example was a good idea, thanks! I added it
5. divbzero ◴[] No.25005506[source]
This is really cool. Gives you much of what jq does without having to remember jq syntax.
6. emmelaich ◴[] No.25005522[source]
Augtool from the Augeas project too. (As well as the mentioned gron)
replies(1): >>25005552 #
7. emmelaich ◴[] No.25005552[source]
example

   $ augtool -r . --noautoload --transform "Json.lns incl /sirdb-example.json" <<EOF
   > print /files/sirdb-example.json/
   > EOF
   /files/sirdb-example.json
   /files/sirdb-example.json/dict
   /files/sirdb-example.json/dict/entry[1] = "_owner"
   /files/sirdb-example.json/dict/entry[1]/string = "nouser"
   /files/sirdb-example.json/dict/entry[2] = "username"
   /files/sirdb-example.json/dict/entry[2]/string = "nouser"
   /files/sirdb-example.json/dict/entry[3] = "email"
   .... etc ...
replies(1): >>25008411 #
8. chousuke ◴[] No.25008411{3}[source]
I find it unfortunate that augeas is so magical. Or rather, the design of its interface is very surprising

What's up with requiring "--noautoload"? What does "-r ." do? and the transform invocation starts with the seemingly magical "Json.lns" (where does it come from?) and appears to refer to a file at the root of the filesystem hierarchy?

I'd probably use augtool more often myself, but its UI is seriously inscrutable.

replies(1): >>25012012 #
9. emmelaich ◴[] No.25012012{4}[source]
I agree, fwiw.

I'm writing a little program to make this whole lot easier.

Answers: by default, augtool loads all the lenses and scans the entire default filesystem (typically /etc); `--noautoload` prevents that.

The -r is `--root`; specify the root as the current directory rather than /