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

adds a basic CLI #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jwarner112
Copy link

I wanted to be able to invoke this on the CLI to extract some data from a folder of JSON files. JQ doesn't implement RFC-9535 yet, so this is the next best thing but had no CLI. I've added a basic one -- define the query, pipe JSON to it via stdin, et voila. Example:

$ echo '{"lorem":{"ipsum":{"dolor":[{"sit":true,"amet":{"hello":"world"}},{"sit":false,"amet":{"foo":"bar"}}]}}}' | go run ./cmd/jsonpath/... "\$.lorem.ipsum.dolor[?(@.sit == true)].amet" | jq .
[
  {
    "hello": "world"
  }
]

@jwarner112 jwarner112 mentioned this pull request Feb 3, 2025
@jwarner112
Copy link
Author

this has some very rough edges, for instance if the JSONpath is nonsense in some way it panics. it also doesn't respond with exit codes. so consider this a starting point.

@theory
Copy link
Owner

theory commented Feb 16, 2025

I like the idea of a jq-like tool that uses RFC 9535 jsonpath expressions. This seems like a nice start to play around with, though I personally lean toward designing something more like a well thought-out app with proper error handling, options, docs, etc. Maybe call it something like jpq :-)

Is this something you'd like to keep working on?

@jwarner112
Copy link
Author

Given the time and space, I'd love to work on it AND make it something more polished than this. I don't think it's nearly release-ready. But at present I wrote it purely to unblock myself on a work task and I'm not sure when I'd personally be able to come back to it. I don't mind if this doesn't get merged in, my fork unblocks me for now and I wouldn't want to introduce such a kluge upstream unless there were immediate plans to fix it up. 👍

@jwarner112
Copy link
Author

jwarner112 commented Feb 21, 2025

Having written the above, it occurs to me a big blocker for me is deciding exactly how someone else's CLI should behave. If you had a think and decided on how you'd like it to work, me or any other contributor are more likely to be able implement it?

@theory
Copy link
Owner

theory commented Feb 22, 2025

I don't have strong feelings about it in advance, no, other than I like short names where possible. My first thought is to mimic how jq works, but it also has pretty unusual syntax that I can never remember. I think starting out with something simple that selects and shows values from STDIN, a file, or option — and perhaps has a pretty-printing (and color?) option — would be nice. I'll be happy to collaborate on the design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants