Threads for tednaleid

  1. 17

    Gron! It transforms JSON into greppable lines like path.to.items[3] = value, and if you like you can edit the result and use gron to transform the edited stuff back to JSON. This brings JSON structures into the line-oriented sed/grep/awk universe – I’m looking at you, Jupyter notebooks. I’ve only had gron for a few months, and it’s already my 13th-most-used command.

    Example output (gron can read from stdin, files, and even URLs):

    ▶ gron testdata/two.json 
    json = {};
    json.contact = {};
    json.contact.email = "mail@tomnomnom.com";
    json.contact.twitter = "@TomNomNom";
    json.github = "https://github.com/tomnomnom/";
    json.likes = [];
    json.likes[0] = "code";
    json.likes[1] = "cheese";
    json.likes[2] = "meat";
    json.name = "Tom";```
    
    1. 2

      Thanks for mentioning this! I had no idea this existed, but is definitely in line with how my brain works vs jq. Even though I use jq almost daily, I can never remember some of the syntax.

      1. 4

        I created an alias for jq, called jqpath, that leverages fzf to give searchable output similar to gron, but that emits it in jq’s expected format: https://twitter.com/tednaleid/status/1302477635914739713

        1. 1

          Oh wow, I just noticed @mrcruz’s recommendation of xml2, elsewhere on this page, which does something similar for HTML and XML. Although for HTML I had hoped it would include element classes and IDs in the path — .../div/div/... is not useless, but .../div.comment#c_tez5vc/div.details/... would have provided more orientation points. Still, this is going in my toolbox; and I thought you might like it, too.

          Part of the output of curl https://lobste.rs/s/eprvjp/what_are_your_favorite_non_standard_cli | html2:

          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/a/@href=/u/loc
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@srcset=/avatars/loc-16.png 1x, /avatars/loc-32.png 2x
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@class=avatar
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@alt=loc avatar
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@src=/avatars/loc-16.png
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@width=16
          /html/body/div/div/ol/li/ol/li/div/div/div/a/img/@height=16
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/a/@href=/u/loc
          /html/body/div/div/ol/li/ol/li/div/div/div/a/@class
          /html/body/div/div/ol/li/ol/li/div/div/div/a=loc
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/span/@title=2020-10-22 17:16:17 -0500
          /html/body/div/div/ol/li/ol/li/div/div/div/span=2 days ago
          /html/body/div/div/ol/li/ol/li/div/div/div= | 
          /html/body/div/div/ol/li/ol/li/div/div/div/a/@href=/s/eprvjp/what_are_your_favorite_non_standard_cli#c_tez5vc
          /html/body/div/div/ol/li/ol/li/div/div/div/a=link
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/span/@class=flagger flagger_stub
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/span/@class=reason
          /html/body/div/div/ol/li/ol/li/div/div/div/span= 
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/@class=comment_text
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          /html/body/div/div/ol/li/ol/li/div/div/div/p=Thanks for mentioning this! I had no idea this existed, but is definitely in line with how my brain works vs 
          /html/body/div/div/ol/li/ol/li/div/div/div/p/code=jq
          /html/body/div/div/ol/li/ol/li/div/div/div/p=. Even though I use 
          /html/body/div/div/ol/li/ol/li/div/div/div/p/code=jq
          /html/body/div/div/ol/li/ol/li/div/div/div/p= almost daily, I can never remember some of the syntax.
          /html/body/div/div/ol/li/ol/li/div/div/div= 
          
          
      1. 5

        in bash scripts, using set -x to emit all of the commands that are being executed (and turning it off with set +x). Lets you quickly figure out what is wrong with the script.

        1. 2

          Neat! I love single purpose shell utilities composes with other commands (“do one thing well”). I like that this also plays nicely with jq, which is one of my favorite tools.

          For me, small, standalone binaries like this are where golang shines brightest. I created a cmdline tool called ganda (https://github.com/tednaleid/ganda) that can take thousands of piped urls and it’ll download them all in parallel and pipe the results on stdout to something like jq (or save to a file). I think the json output of tj might fit well with this, I’ll give it a shot.