Skip to main content

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']

Release files for json2unique 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json2unique 1.0.0
File Size Uploaded
json2unique-1.0.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json2unique 1.0.0
File Interpreter ABI Platform
json2unique-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / json2unique-1.0.0.tar.gz

Download URL json2unique-1.0.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ba3c58efef338e8261b387df72069afc997107a160196e59b0655e7e336ec776
BLAKE2b-256 checksum
How to use checksums
e9775d2eb06bbace1eb2f17352071481c242d51f3ef2017fbce678d6ca879982
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release files / json2unique-1.0.0-py3-none-any.whl

Download URL json2unique-1.0.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71af0e0da28ce5e48c640c63069039840ba0b482e9ee1a0543b2a00816ccb38e
BLAKE2b-256 checksum
How to use checksums
eeb9fc2c8a10c0c6f73bd9bf8c139a275221537ce784b654f8bce42cc83582e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page