Comments (4)
Maybe --stream
in combination with setpath
could be used? something like this:
$ echo '{"a": [1,2,{"c":123},"b":767' | jq --stream | jq -n 'reduce inputs as $i ({}; if ($i | has(1)) then setpath($i[0]; $i[1]) else . end)'
parse error: ':' not as part of an object at line 1, column 25
{
"a": [
1,
2,
{
"c": 123
}
]
}
I tried to use fromstream
but could not get it to work with a "broken" stream.
from jq.
I don't think I'll be doing this. It seems really specific to your log format. Generally, when the input makes no sense, I want to tell the user that the input makes no sense, rather than picking some meaning at random and running with it. Down that road lies PHP.
For your particular problem, have you considered just fixing it with sed before you pipe to jq? `sed 's/^[//;s/,$//' will delete '[' at the start of a line and commas at the end, which should leave you with one object per line (a format jq understands).
Incidentally, one JSON object per line with no other structure is a pretty sensible format: most languages have readline() and parseJSON(), and the format stays valid when cat'd, grep'd or logrotate'd.
from jq.
I think adding partial parsing support for truncated json would be valuable, sometimes you get some and it would be really good to be able to use jq
to inspect it. This could be only enabled via an option, so normally it should of course fail when invalid json is parsed.
from jq.
Oh, that workaround is already something! Nice!
from jq.
Related Issues (20)
- CVE-2023-49355 status ? HOT 2
- Tests don't work in non-decnumber builds
- Feature Request - Full Path Json output HOT 5
- Broken non-Latin output HOT 14
- Version 1.7.1 not working well on XcodeCloud HOT 4
- 1 test fails on WSL Debian HOT 14
- Version number pattern
- Base64d filter is not working as expected. HOT 2
- Allow user to control colors of int/bool/number HOT 2
- Incorrect results when subtracting two long numbers HOT 2
- make test failed under WSL, version jq 1.7.1-8-gf51e841 HOT 3
- Adding `sort_keys` filter as a flexible alternative to `--sort-keys` HOT 10
- Typo in the manual HOT 1
- try-catch + ascii_downcase fails in "catch" condition HOT 5
- Error suppression operator breaks function behaviour HOT 2
- Unrecognized HTML entity: `©` while running xq command HOT 1
- Setting non-existent elements of array slices uncovers hidden elements
- nan123 HOT 6
- Feature: Allow keys/array strings to be different color than object keys
- Modulo operator drops fractional part HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.