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
File details
Details for the file json2unique-1.0.0.tar.gz
.
File metadata
- Download URL: json2unique-1.0.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba3c58efef338e8261b387df72069afc997107a160196e59b0655e7e336ec776 |
|
MD5 | 23af84a87422d8eb98601e395a26266f |
|
BLAKE2b-256 | e9775d2eb06bbace1eb2f17352071481c242d51f3ef2017fbce678d6ca879982 |
File details
Details for the file json2unique-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: json2unique-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71af0e0da28ce5e48c640c63069039840ba0b482e9ee1a0543b2a00816ccb38e |
|
MD5 | 9f1a65ad786df7c8a7d6833ac69dfe41 |
|
BLAKE2b-256 | eeb9fc2c8a10c0c6f73bd9bf8c139a275221537ce784b654f8bce42cc83582e0 |