Code Monkey home page Code Monkey logo

Comments (17)

mwilliamson avatar mwilliamson commented on July 29, 2024

No, there's no support for slurp. Mind if I ask what your use case is?

from jq.py.

librarianmage avatar librarianmage commented on July 29, 2024

I am trying to combine multiple JSON arrays (in strings) into one, and
while reading on the jq documentation, which I am already using for its
more common uses, I noticed the "slurp" option.

On Fri, Jan 15, 2016 at 6:35 PM Michael Williamson [email protected]
wrote:

No, there's no support for slurp. Mind if I ask what your use case is?


Reply to this email directly or view it on GitHub
#17 (comment).

from jq.py.

librarianmage avatar librarianmage commented on July 29, 2024

By looking further into the manual, I found that .[0] + .[1] does exactly what I need.

from jq.py.

metashock avatar metashock commented on July 29, 2024

Can this get re-opened? My use case is to replace Subprocess calls to jq by using this extension. This requires that the extension offer the same feature set as the command line binary. Just from a short look into the source code of jq it should being possible to use the slurp mode with the library.

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

What's your use case? Just trying to understand why explicitly passing in an array wouldn't work.

from jq.py.

metashock avatar metashock commented on July 29, 2024

Let's say you have this input:

{"name":"Bob Dylan", "tags":"{Artist}{Singer}"}{"name": "Michael Jackson"}

which is not valid json but a stream of valid json objects. The following jq command:

jq -s . input.txt

gives you a valid json array:

[
  {
    "name": "Bob Dylan",
    "tags": "{Artist}{Singer}"
  },
  {
    "name": "Michael Jackson"
  }
]

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

Ah, I see. Seems reasonable. I don't really have time to add new functionality, but feel free to make a pull request.

from jq.py.

metashock avatar metashock commented on July 29, 2024

@mwilliamson Ok. Let me dig into it.. I'll give my best! :)

from jq.py.

peterthomassen avatar peterthomassen commented on July 29, 2024

This relates to --slurpfile which allows reading in and processing multiple files. The can be referred to using variables in the jq filter:

jq -n --slurpfile old $1 --slurpfile new $2 '{old: $old[0], new: $new[0]}'

If someone was working on slurp functionality, it may be worth considering this as well.

My use case is computing a JSON that represents something like the diff between old and new.

from jq.py.

henricook avatar henricook commented on July 29, 2024

+1 - I was using this library through urlwatch and wanted to be able to slurp as I'm handling a list of objects (not wrapped in an array) from an HTTP endpoint

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

I've added slurp functionality and released a prerelease version to PyPI. Feedback would be welcome!

from jq.py.

BYK avatar BYK commented on July 29, 2024

@mwilliamson any plans on releasing the slurp-enabled version as a full release?

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

As above, some feedback would be useful to know if the current implementation actually solves the problem or not before making a release.

from jq.py.

BYK avatar BYK commented on July 29, 2024

Well, don't know about the case above but it certainly works for me and works as expected 🙂

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

This has now been released as part of 1.5.0.

from jq.py.

peterthomassen avatar peterthomassen commented on July 29, 2024

Thanks, @mwilliamson! 🎉

From the code, I gather that referring to different inputs using variables in the jq filter, like in jq, hasn't been implemented:

jq -n --slurpfile old $1 --slurpfile new $2 '{old: $old[0], new: $new[0]}'

Is that right? -- I can open a separate feature request issue for that, just would like to make sure.

(My use case is computing a JSON that represents something like the diff between two inputs, which currently requires invocation of jq as a separate process.)

from jq.py.

mwilliamson avatar mwilliamson commented on July 29, 2024

Correct, the change is only to add the slurp argument to input_text().

from jq.py.

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.