Query language to filter Json

There is any kind of package to do json filter in Elixir? I’m looking for something similar to https://github.com/stedolan/jq.

The idea is to process a stream of content and based on a user generated query, forward the content to other clients. The query should be something like this:

(old.stock == 0 && new.stock > 0) || (old.stock > 0 && new.stock == 0)

Changesets don’t filter a stream. Stream.filter does, but I don’t know that we have a streaming JSON parser in Elixir. If you stream chunks out of a file, they won’t be valid JSON since the closing tag is at the end of the file. I think jq and other streaming parsers adopt a relaxed attitude with regard to closing tags.

1 Like

Your ‘JSON Stream’ has to be a JSON array, for it to contain multiple elements.

In that case, you can try to remove the opening [, and try to parse the rest as separate JSON objects, maybe.

1 Like

No, it could be an object that contains an array as a member object. It is not a trivial problem.

PostgreSQL might know how to do that :wink: (okay that’s overengineered.)

@Neurofunk haha, yes, overengineered and slow. It need to be blazing fast as it gonna process Kinesis streams.

Well, i didn’t found anything ready to do it. I think i will need to implement it.

1 Like