Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter line-delimited or streaming JSON without slurping #292

Closed
inosik opened this issue Mar 5, 2024 · 2 comments
Closed

Filter line-delimited or streaming JSON without slurping #292

inosik opened this issue Mar 5, 2024 · 2 comments

Comments

@inosik
Copy link

inosik commented Mar 5, 2024

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.

@antonmedv
Copy link
Owner

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'

@inosik
Copy link
Author

inosik commented Mar 5, 2024

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

@inosik inosik closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants