Parses the json document into a list of unique elements
Project description
JSON To Unique
Parses the JSON document into a list of unique elements
Instructions
json2unique --help
usage: json2unique [-h] [-d DEPTH] [infile] [outfile]
JSON parser
positional arguments:
infile the path to the JSON file to be parsed
outfile the path to the output file
optional arguments:
-h, --help show this help message and exit
-d DEPTH, --depth DEPTH
set maximum recursion depth
If the optional infile
or outfile
arguments are not passed to utility, STDIN
and STDOUT
will be considered as default values.
For large JSON files with many nested objects, you can manually increase the recursion depth using -d
flag. The default value is 10_000
.
Usage
Command Line Interface
You can use this package both as a CLI utility and as a library. Here is an example of how to use it in the terminal:
json2unique array.json
[1, 2, 42]
You can use Unix pipes to read STDIN and write to STDOUT streams:
echo '{"a": 1}' | json2unique > result.txt
cat result.txt
[1, 'a']
Manually type the desired JSON in the terminal (press Ctrl+D
when finish typing):
json2unique
{"a": [34, "hello", -343.56]}
['a', -343.56, 34, 'hello']
Use standard CLI Unix utilities to process the program's output:
json2unique array.json | grep 42
[1, 2, 42]
If there is a non-valid JSON, json2unique
will throw an appropriate exception and terminate with a non-zero code:
echo '{"a": 1""}' | json2unique
Expecting ',' delimiter: line 1 column 8 (char 7)
Last exit code is:
echo $?
1
Python Library
To use this module as a library, enter the following line:
import json2unique
json2unique.parse_json_to_list_of_unique({"a": 1}) # [1, 'a']
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for json2unique-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71af0e0da28ce5e48c640c63069039840ba0b482e9ee1a0543b2a00816ccb38e |
|
MD5 | 9f1a65ad786df7c8a7d6833ac69dfe41 |
|
BLAKE2b-256 | eeb9fc2c8a10c0c6f73bd9bf8c139a275221537ce784b654f8bce42cc83582e0 |