Skip to content

Conversation

@hakanw
Copy link
Contributor

@hakanw hakanw commented Jan 28, 2014

This script is based on https://github.com/makefu/jsonpath but expanded to work well with batches of files, globbing etc.

It will be installed as a bin/ script, so pip installing this package also gives a useful tool for testing and doing stuff. This is really useful, and I had a hard time finding a working JSONpath script (there are so many outdated, or for old versions of perl and what not).

There are two modes: stdin input and file path input

Examples:

$ echo '{ "foobar": 1 }' | jsonpath.py foobar
1
$ jsonpath.py $..myelement *.json
lots of output
here
for every myelement
...

Please merge! :)

…ut improved and expanded) that will be installed in bin/. this means anyone installing this package will also get a jsonpath.py that will work on the command line
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past I've used something like

    entry_points = {
        'console_scripts': ['jsonpath = jsonpath_rw.cli:entry_point']
    }

Two things I really like about that are:

  1. You can test the function easily
  2. The name of the script is independent

Is there any pitfall to this method? I know the packaging situation is confusing in Python so I could have got something wrong.

@kennknowles
Copy link
Owner

Overall, this is a great idea. I've dropped a few specific comments just on little improvements. Any of them that you would care to take on would be super. I can do the rest, but it will get done sooner if you do :-)

kennknowles added a commit that referenced this pull request Feb 7, 2014
Add jsonpath.py script that can be used when installing this package
@kennknowles kennknowles merged commit b01e2e5 into kennknowles:master Feb 7, 2014
@kennknowles
Copy link
Owner

Didn't mean to leave this sitting here. Thanks!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this. This makes it break when the files have special characters in their name. Globbing is the shell's job. Do you actually require this? Is this a Windows thing?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Just discovered that, at least at the time of some SO answers, DOS/Windows shell does not glob.This behavior is a bug in the DOS/Windows shell. I'll leave this in until someone on a unixy OS reports a bug, at which point I'll be forced to fix this to not glob. It is just a rare corner case so who knows if it will ever come up.

@kennknowles
Copy link
Owner

This is available in the new 1.3.0 release on PyPi

@hakanw
Copy link
Contributor Author

hakanw commented Mar 2, 2014

Sorry for taking so long to get back, I noticed just now you had already merged it. Otherwise I would have done the remaining work now.

Thanks!

@kennknowles
Copy link
Owner

No worries. Thanks for the contribution!

@kennknowles kennknowles mentioned this pull request Jan 22, 2015
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