1. 9

  2. 3

    If this is interesting, I hope you know about jq, which is a more-mature tiny functional language for querying and manipulating JSON. It’s a great tool that I reach for a lot now that we live in a JSON-soaked world.


    1. 1

      This looks like it was inspired by jq.

      A problem I have using jq in anger is getting totally lost trying to do complicated things where either the input or desired output objects aren’t flat. e.g. stuff like transposing objects, turning [{spam: true, eggs: true}, {spam: true, eggs: false}] into {spam: [true, true], eggs: [true, false]} I just can’t figure out and I’m not sure if it’s even possible. Id’ normally reach for Node or Python for something like that after half an hour trying to puzzle at jq.

      jl looks like it might help me with that because I understand how to compose things made out of lambda calculus better than I understand how to compose things made out of templates. e.g. If I’ve read the documentation right, it looks like my specific object transpose program above might just be:

      jl '\objs -> {spam: map _.spam objs, eggs: map _.eggs objs}'
      1. 1

        jq is pretty much lambdas; but they all take one argument, so the \objs -> part is implicit.

        Your expression is nearly the same in jq:

        jq '{spam: map(.spam), eggs: map(.eggs)}'

        Or if you don’t know the keys in advance, you could do:

        jq -c 'map(to_entries) | flatten | group_by(.key) | map({(first.key): map(.value)})'