antonmedv/fx

Filter line-delimited or streaming JSON without slurping

inosik opened this issue · 2 comments

Hi, maybe I'm missing something obvious, but it looks like it's currently not possible to filter or map line-delimited files or streamed input without having to use --slurp.

$ echo '{"value": 90}' '{"value": 100}' | fx '.filter(x => x.value >= 100)'

   .filter(x => x.value >= 100)
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

x.filter(x => x.value >= 100)

TypeError: x.filter is not a function
    at Object.eval (eval at run (C:\Users\username\AppData\Local\Temp\fx-31.0.0.js:124:14), <anonymous>:3:16)
    at run (C:\Users\username\AppData\Local\Temp\fx-31.0.0.js:124:25)
    at runTransforms (C:\Users\username\AppData\Local\Temp\fx-31.0.0.js:58:20)
    at async main (C:\Users\username\AppData\Local\Temp\fx-31.0.0.js:42:7)

Other than that, thank you for creating fx! I've been looking for an alternative to jq for some time and fx looks just right.

Yes, without --slurp function applied to each input json.

❯ echo '{"value": 90}' '{"value": 100}' | fx 'typeof(x)'
object
object

So your error is about:

{"value": 90}.filter(x => x.value >= 100)
// TypeError: x.filter is not a function

If you want to filter without slurping use skip keywork.

echo '{"value": 90}' '{"value": 100}' | fx 'x.value >= 100 ? x : skip'

Thank you for your quick answer, this works. As I said, pretty obvious 😅