Converts nested json object to csv and csv back to json
Project description
libjson2csv
========
*Converts nested json object to csv and csv back to json*
This package provides functionality to convert valid nested json objects/files to csv and vice versa.
Written in python 3
Usage
-----
To convert json to csv
```
usage: python -m libjson2csv.json_2_csv [--m] <json_in_file_path> [<csv_out_file_path>]
```
To convert csv to json
```
usage: python -m libjson2csv.csv_2_json <csv_in_file_path> [<json_out_file_path>]
```
If the output file path is not provided the output will be dumped to STDOUT.
Specifications
--------------
Scripts expects a valid json.
* JSON can be a valid nested object or a list.
* Script will convert each item of the list to a corresponding row in the csv.
* If JSON is dictionary the outputted csv will contain single row.
Example:
*Converts JSON*
```json
{
"key_1_1": "val_1_1_1",
"key_1_2": [
"val_1_2_1",
"val_1_2_2",
"val_1_2_3"
],
"key_1_3": [{
"key_1_3_2_1": "val_1_3_2_1_1"
}, {
"key_1_3_2_1": "val_1_3_2_1_2"
}, {
"key_1_3_2_1": "val_1_3_2_1_3"
}],
"key_1_4": {
"key_1_4_2_1": "val_1_4_2_1_1"
},
"key_1_5": {
"key_1_5_2_1": [{
"key_1_5_2_3_1": "val_1_5_2_3_1_1"
}]
}
}
```
*TO*
Without `--m` flag
|key_1_1 | key_1_2[0] | key_1_2[1] | key_1_2[2] | key_1_3[0].key_1_3_2_1 | key_1_3[1].key_1_3_2_1 | key_1_3[2].key_1_3_2_1 | key_1_4.key_1_4_2_1 | key_1_5.key_1_5_2_1[0].key_1_5_2_3_1|
|----|----|----|----|----|----|----|----|----|
|val_1_1_1 | val_1_2_1 | val_1_2_2 | val_1_2_3 | val_1_3_2_1_1 | val_1_3_2_1_2 | val_1_3_2_1_3 | val_1_4_2_1_1 | val_1_5_2_3_1_1|
With `--m` flag
|*key_1_2|key_1_1|key_1_3[0].key_1_3_2_1|key_1_3[1].key_1_3_2_1|key_1_3[2].key_1_3_2_1|key_1_4.key_1_4_2_1|key_1_5.key_1_5_2_1[0].key_1_5_2_3_1|
|----|----|----|----|----|----|----|
|val_1_2_1;val_1_2_2;val_1_2_3|val_1_1_1|val_1_3_2_1_1|val_1_3_2_1_2|val_1_3_2_1_3|val_1_4_2_1_1|val_1_5_2_3_1_1|
`--m` stores a simple list in a single column with items separated by a semicolon.
0.1.0 (2017-04-15)
------------------
- Initial version.
========
*Converts nested json object to csv and csv back to json*
This package provides functionality to convert valid nested json objects/files to csv and vice versa.
Written in python 3
Usage
-----
To convert json to csv
```
usage: python -m libjson2csv.json_2_csv [--m] <json_in_file_path> [<csv_out_file_path>]
```
To convert csv to json
```
usage: python -m libjson2csv.csv_2_json <csv_in_file_path> [<json_out_file_path>]
```
If the output file path is not provided the output will be dumped to STDOUT.
Specifications
--------------
Scripts expects a valid json.
* JSON can be a valid nested object or a list.
* Script will convert each item of the list to a corresponding row in the csv.
* If JSON is dictionary the outputted csv will contain single row.
Example:
*Converts JSON*
```json
{
"key_1_1": "val_1_1_1",
"key_1_2": [
"val_1_2_1",
"val_1_2_2",
"val_1_2_3"
],
"key_1_3": [{
"key_1_3_2_1": "val_1_3_2_1_1"
}, {
"key_1_3_2_1": "val_1_3_2_1_2"
}, {
"key_1_3_2_1": "val_1_3_2_1_3"
}],
"key_1_4": {
"key_1_4_2_1": "val_1_4_2_1_1"
},
"key_1_5": {
"key_1_5_2_1": [{
"key_1_5_2_3_1": "val_1_5_2_3_1_1"
}]
}
}
```
*TO*
Without `--m` flag
|key_1_1 | key_1_2[0] | key_1_2[1] | key_1_2[2] | key_1_3[0].key_1_3_2_1 | key_1_3[1].key_1_3_2_1 | key_1_3[2].key_1_3_2_1 | key_1_4.key_1_4_2_1 | key_1_5.key_1_5_2_1[0].key_1_5_2_3_1|
|----|----|----|----|----|----|----|----|----|
|val_1_1_1 | val_1_2_1 | val_1_2_2 | val_1_2_3 | val_1_3_2_1_1 | val_1_3_2_1_2 | val_1_3_2_1_3 | val_1_4_2_1_1 | val_1_5_2_3_1_1|
With `--m` flag
|*key_1_2|key_1_1|key_1_3[0].key_1_3_2_1|key_1_3[1].key_1_3_2_1|key_1_3[2].key_1_3_2_1|key_1_4.key_1_4_2_1|key_1_5.key_1_5_2_1[0].key_1_5_2_3_1|
|----|----|----|----|----|----|----|
|val_1_2_1;val_1_2_2;val_1_2_3|val_1_1_1|val_1_3_2_1_1|val_1_3_2_1_2|val_1_3_2_1_3|val_1_4_2_1_1|val_1_5_2_3_1_1|
`--m` stores a simple list in a single column with items separated by a semicolon.
0.1.0 (2017-04-15)
------------------
- Initial version.
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
libjson2csv-0.0.7.tar.gz
(5.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libjson2csv-0.0.7.tar.gz.
File metadata
- Download URL: libjson2csv-0.0.7.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdf980a2ef45cc59c3f1f434a752cbd1c017e1d7e347c5d34b3dcc7026537be2
|
|
| MD5 |
2ed1385c0d7f0eb8f6359d73471aad74
|
|
| BLAKE2b-256 |
4ca926bc2eaec8a29ad95542d5c220aec4fb131a7a58ac46776a2ecbf9eae184
|
File details
Details for the file libjson2csv-0.0.7-py3-none-any.whl.
File metadata
- Download URL: libjson2csv-0.0.7-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6bb2568ff1be9852137e2e105a5b3c9aa7f29c637293fe9997ef0743ae44357
|
|
| MD5 |
479d6518cd7191d257180091ad5d026b
|
|
| BLAKE2b-256 |
1977b01dee122a5e85a96e740c1cebe1b288540f8047bce5c6d87003c68959f2
|