gorp version 0.2.4, which contains gorp.jsonpath 0.2.0, is now available on the
Python package index. It has been tested for Python 3.6 to 3.9.
Added
- '-g' option for reading a series of gorp directives from a text file.
Currently this can only be done from the command line, not during an
interactive session or while working in a Python shell. This will change soon.
- Aggregation functionality for jsonpath akin to aggregates with GROUP BY in
SQL. For instance, for some JSON file you could use "AGG sum BY 0" to calculate
the sum of all the lowest-level values (like likes on Facebook or whatever)
grouped by the keys at the highest level (0, the first node on the path).
You can use the "max", "min", "avg"|"mean", "sum", "len"|"count" functions,
or make your own in situ using "f(x)" syntax like `"sum(``float`` map y)\*3"`.
- Documentation for the new aggregation functionality in gorp/option_docs,
gorp/jsonpath/aggregate.py and gorp/jsonpath/jsonpath.py.
- Test suites for the -x, -e, -w, and -z options.
Changed
- jsonpath is now a subpackage rather than a module. The core API of JsonPath
and json_extract is in jsonpath/jsonpath.py, the Filter and GlobalConstraint
classes are in jsonpath/filters.py, the Mutator class and mutate_json
functions are in jsonpath/mutate.py, the parser functions are in
jsonpath/parser.py, and the new aggregation functionality is in
jsonpath/aggregate.py.
- Negative integer arguments can be used to constrain the number of files
shown. This is particularly useful in combination with the -m and -s options,
because it allows the user to see the smallest or the oldest files in a set.
- -z option no longer includes the entire hierarchy of parent directories
leading to a file in zipped file names. Previously, if you used the -z option
to zip "C:/Users/mjols/Python39/foo.py" and "C:/Users/mjols/bar.txt" together,
you'd have to navigate through a bunch of folders containing one subfolder and
nothing else to get to the files. Now os.path.commonpath is used to determine
that e.g., those two files could be zipped together as "Python39/foo.py" and
"bar.txt" without loss of meaningful information.
Fixed
- -e option for reading resultsets in from files was broken. Now it works for
both YAML and JSON files.
- Some extensions in gorp.utils.textTypeFiles were changed to all lower-case.
They have to be because extensions are coerced to lower-case before checking
membership in textTypeFiles for the -f option and most text-reading options.
- -x option for reading XML and HTML did not return all results. Now it returns
every match to an XPath or CSS selector, in the form of the full text of the
matched element, including tags. Since there are likely to be multiple
elements with the same tag with the same parents in an XML or HTML document,
the "path" to an element for purposes of the -n option is treated as
(root, ancestor_2, ..., ancestor_n, ii), where ii is the 0-indexed position of
the element in the list of elements with the same tag and the same ancestors.