Giter VIP home page Giter VIP logo

Comments (4)

wader avatar wader commented on July 4, 2024 3

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.

stedolan avatar stedolan commented on July 4, 2024

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.

lucatpa avatar lucatpa commented on July 4, 2024

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.

lucatpa avatar lucatpa commented on July 4, 2024

Oh, that workaround is already something! Nice!

from jq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.