Skip to main content

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: json_2_csv.py [--minimize-columns] <json_in_file_path> <csv_out_file_path>
```

To convert csv to json
```
usage: csv_2_json.py <csv_in_file_path> <json_out_file_path>
```

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 `--minimize-columns` 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 `--minimize-columns` 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|

`--minimize-columns` stores a simple list in a single column with items separated by a semicolon.

0.1.0 (2017-04-15)
------------------
- Initial version.

Project details


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.5.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libjson2csv-0.0.5-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file libjson2csv-0.0.5.tar.gz.

File metadata

  • Download URL: libjson2csv-0.0.5.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for libjson2csv-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ddb23e554cc6c1eb89b64c309d3d9881530be53181096f8f4bc0797bdffab088
MD5 01fd5ac03417a02e79559dff91afcf04
BLAKE2b-256 0fd4be1dc89359db18994f13dc0dcb25133183cb9e7b0f65e8d6e64f5eaaab79

See more details on using hashes here.

File details

Details for the file libjson2csv-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for libjson2csv-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1ea3324077a095ac0c0971bc08b86f46d263eef81dbcc4e1fd492b8f88fc16f9
MD5 f76d8e24f948e4c8d21accb4876da99a
BLAKE2b-256 b65d5aaff312e327aa8f8eb2d8bd2350f6e39101a6be640499938c15a2a49a36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page