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

Add support for parsing ndjson #578

Open
dekelpilli opened this issue Nov 23, 2023 · 0 comments
Open

Add support for parsing ndjson #578

dekelpilli opened this issue Nov 23, 2023 · 0 comments
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library

Comments

@dekelpilli
Copy link

dekelpilli commented Nov 23, 2023

I've recently come across a problem that would be more conveniently solved if I could parse ndjson strings within VRL. This could also extend to concatenated JSONs (e.g. {"a":1}{"a":2}), or JSONs with a delimiter other than newlines.

I'm not sure exactly what would be the best approach for this feature would be, but I guess it would likely be one of the following:

s = s'{"a":1}\n{"a":2}\n0'

parse_json!(s, format: 'ndjson') # [{"a":1}, {"a": 2}, 0]

# or 

parse_json_stream!(s, delimiter: '\n') # [{"a":1}, {"a": 2}, 0]
parse_json_stream!(s'{"a":3}{"a":4}0') # [{"a":3}, {"a": 4}, 0]

You can achieve something similar with the split +parse_json function, but that doesn't fail fast on JSONs across lines: {"a":"sentence"}\n{"a":"sentence\nwith\nnewlines"}, and doesn't help with parsing JSON streams with no delimiter (e.g. {"a":1}{"a":2})

@bruceg bruceg added vrl: stdlib Changes to the standard library type: feature A value-adding code addition that introduce new functionality. labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library
Projects
None yet
Development

No branches or pull requests

2 participants