# JSON Duplicate Keys - PyPI
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
<p align="center">
<a href="https://github.com/truocphan/json-duplicate-keys/releases/"><img src="https://img.shields.io/github/release/truocphan/json-duplicate-keys" height=30></a>
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
<a href="https://github.com/truocphan/json-duplicate-keys/issues?q=is%3Aopen+is%3Aissue"><img src="https://img.shields.io/github/issues/truocphan/json-duplicate-keys" height=30></a>
<a href="https://github.com/truocphan/json-duplicate-keys/issues?q=is%3Aissue+is%3Aclosed"><img src="https://img.shields.io/github/issues-closed/truocphan/json-duplicate-keys" height=30></a>
</p>
## Installation
#### From PyPI:
```console
pip install json-duplicate-keys
```
#### From Source:
```console
git clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>
cd json-duplicate-keys
python setup.py build
python setup.py install
```
## Basic Usage
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
_Normalize Key name_
- `name`: key name
- `dupSign_start`:
- `dupSign_end`:
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
print(jdks.normalize_key("version{{{_2_}}}"))
# OUTPUT: version
```
---
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
- `Jstr`: a JSON format string
- `dupSign_start`:
- `dupSign_end`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject)
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>
```
---
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
- `Jfilepath`: The path to the file containing the JSON format string
- `dupSign_start`:
- `dupSign_end`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/ Hide debug error messages
```python
# /path/to/file.json: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
import json_duplicate_keys as jdks
Jfilepath = "/path/to/file.json"
JDKSObject = jdks.load(Jfilepath)
print(JDKSObject)
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>
```
---
### JSON_DUPLICATE_KEYS.getObject()
_Get the JSON object_
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
```
---
### JSON_DUPLICATE_KEYS.get(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
_Get value in the JSON object by `name`_
- `name`: the key name of the JSON object. Supported flatten key name format
- `case_insensitive`: the key name case (in)sensitive
- `separator`:
- `parse_index`:
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.get("version{{{_2_}}}"))
# OUTPUT: latest
print(JDKSObject.get("release||$0$"))
# OUTPUT: {'version': 'latest'}
print(JDKSObject.get("snapshot||author"))
# OUTPUT: truocphan
```
---
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
_Set a new `name` and `value` for the JSON object_
- `name`: new key name for the JSON object. Supported flat key name format
- `value`: value for key `name`
- `case_insensitive`: the key name case (in)sensitive
- `separator`:
- `parse_index`:
- `dupSign_start`:
- `dupSign_end`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {}
JDKSObject.set("author", "truocphan")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan'}
JDKSObject.set("version", "22.3.3")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}
JDKSObject.set("version", "latest")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}
JDKSObject.set("release", [{"version": "latest"}])
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}
JDKSObject.set("snapshot", {})
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}
JDKSObject.set("snapshot||author", "truocphan")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
Jstr = '[]'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: []
JDKSObject.set("author", "truocphan")
print(JDKSObject.getObject())
# OUTPUT: [{'author': 'truocphan'}]
JDKSObject.set("release", [])
print(JDKSObject.getObject())
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
JDKSObject.set("$1$||release||", {"version": "latest"})
print(JDKSObject.getObject())
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
```
---
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `allow_new_key`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
- `name`: the key name of the JSON object. Supported flatten key name format
- `value`: new value for key `name`
- `case_insensitive`: the key name case (in)sensitive
- `allow_new_key`: allows to create a new key name if the key name does not exist
- `separator`:
- `parse_index`:
- `dupSign_start`:
- `dupSign_end`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
JDKSObject.update("version{{{_2_}}}", ["22.3.3", "latest"])
JDKSObject.update("snapshot||version", "latest")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}
```
---
### JSON_DUPLICATE_KEYS.delete(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
_Delete a key-value pair in a JSON object by key `name`_
- `name`: the key name of the JSON object. Supported flatten key name format
- `case_insensitive`: the key name case (in)sensitive
- `separator`:
- `parse_index`:
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
JDKSObject.delete("version")
JDKSObject.delete("release||$0$")
JDKSObject.delete("snapshot")
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}
```
---
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
- `name`:
- `separator`:
- `parse_index`:
- `ordered_dict`: preserves the order in which the Keys are inserted
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.filter_keys("version").dumps())
# OUTPUT: {"version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}
print(JDKSObject.dumps())
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
```
---
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
- `value`:
- `separator`:
- `parse_index`:
- `ordered_dict`: preserves the order in which the Keys are inserted
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.filter_values("latest").dumps())
# OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
print(JDKSObject.dumps())
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
```
---
### JSON_DUPLICATE_KEYS.dumps(`dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False, `skipkeys`=False, `ensure_ascii`=True, `check_circular`=True, `allow_nan`=True, `cls`=None, `indent`=None, `separators`=None, `default`=None, `sort_keys`=False)
_Serialize a JSON object to a JSON format string_
- `dupSign_start`:
- `dupSign_end`:
- `_isDebug_`: Show/ Hide debug error messages
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
JDKSObject.delete("version")
JDKSObject.delete("release||$0$")
JDKSObject.delete("snapshot")
print(JDKSObject.dumps())
# OUTPUT: {"author": "truocphan", "version": "latest", "release": []}
```
---
### JSON_DUPLICATE_KEYS.dump(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False, `skipkeys`=False, `ensure_ascii`=True, `check_circular`=True, `allow_nan`=True, `cls`=None, `indent`=None, `separators`=None, `default`=None, `sort_keys`=False)
_Serialize a JSON object to a JSON format string and write to a file_
- `Jfilepath`: the path to the file to save the JSON format string
- `dupSign_start`:
- `dupSign_end`:
- `_isDebug_`: Show/ Hide debug error messages
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
JDKSObject.delete("version")
JDKSObject.delete("release||$0$")
JDKSObject.delete("snapshot")
Jfilepath = "/path/to/file.json"
JDKSObject.dump(Jfilepath)
JDKSObject_load = jdks.load(Jfilepath)
print(JDKSObject_load.getObject())
# OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}
```
---
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
_Flatten a JSON object to a single key-value pairs_
- `separator`:
- `parse_index`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
JDKSObject.flatten()
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}
```
---
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
_Unflatten a flattened JSON object back to a JSON object_
- `separator`:
- `parse_index`:
- `ordered_dict`: preserves the order in which the Keys are inserted
- `_isDebug_`: Show/ Hide debug error messages
```python
import json_duplicate_keys as jdks
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||author": "truocphan", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}'
JDKSObject = jdks.loads(Jstr)
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}
JDKSObject.unflatten()
print(JDKSObject.getObject())
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
```
---
## CHANGELOG
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
- **Fixed**: Add subkey name to empty dict of existing key name
#### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
- **Updated**: Allows getting (`JSON_DUPLICATE_KEYS.get`), setting (`JSON_DUPLICATE_KEYS.set`), updating (`JSON_DUPLICATE_KEYS.update`), deleting (`JSON_DUPLICATE_KEYS.delete`) JSON_DUPLICATE_KEYS objects with case-insensitive key names
#### [json-duplicate-keys v2024.7.17](https://github.com/truocphan/json-duplicate-keys/tree/2024.7.17)
- **Fixed**: issue [#3](https://github.com/truocphan/json-duplicate-keys/issues/3) break the set function when the key's value is empty. Thanks [ptth222](https://github.com/ptth222) for reporting this issue.
#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
- **New**: _filter_values_
- **Updated**: _filter_keys_
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
---
Raw data
{
"_id": null,
"home_page": "https://github.com/truocphan/json-duplicate-keys",
"name": "json-duplicate-keys",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "TPCyberSec, json, duplicate keys, json duplicate keys, flatten, unflatten",
"author": "TP Cyber Security",
"author_email": "tpcybersec2023@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e0/dd/c8786d1f1d6ad8c42dd51d365e5717a201c00f3531a479b6b23b0ee2c8f3/json_duplicate_keys-2024.11.28.tar.gz",
"platform": null,
"description": "# JSON Duplicate Keys - PyPI\nFlatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys\n\n<p align=\"center\">\n <a href=\"https://github.com/truocphan/json-duplicate-keys/releases/\"><img src=\"https://img.shields.io/github/release/truocphan/json-duplicate-keys\" height=30></a>\n\t<a href=\"#\"><img src=\"https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total\" height=30></a>\n\t<a href=\"#\"><img src=\"https://img.shields.io/github/stars/truocphan/json-duplicate-keys\" height=30></a>\n\t<a href=\"#\"><img src=\"https://img.shields.io/github/forks/truocphan/json-duplicate-keys\" height=30></a>\n\t<a href=\"https://github.com/truocphan/json-duplicate-keys/issues?q=is%3Aopen+is%3Aissue\"><img src=\"https://img.shields.io/github/issues/truocphan/json-duplicate-keys\" height=30></a>\n\t<a href=\"https://github.com/truocphan/json-duplicate-keys/issues?q=is%3Aissue+is%3Aclosed\"><img src=\"https://img.shields.io/github/issues-closed/truocphan/json-duplicate-keys\" height=30></a>\n</p>\n\n## Installation\n#### From PyPI:\n```console\npip install json-duplicate-keys\n```\n#### From Source:\n```console\ngit clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>\ncd json-duplicate-keys\npython setup.py build\npython setup.py install\n```\n\n## Basic Usage\n### normalize_key(`name`, `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `_isDebug_`=False)\n_Normalize Key name_\n- `name`: key name\n- `dupSign_start`: \n- `dupSign_end`: \n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nprint(jdks.normalize_key(\"version{{{_2_}}}\"))\n# OUTPUT: version\n```\n---\n\n### loads(`Jstr`, `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `ordered_dict`=False, `_isDebug_`=False)\n_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_\n- `Jstr`: a JSON format string\n- `dupSign_start`: \n- `dupSign_end`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject)\n# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>\n```\n---\n\n### load(`Jfilepath`, `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `ordered_dict`=False, `_isDebug_`=False)\n_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_\n- `Jfilepath`: The path to the file containing the JSON format string\n- `dupSign_start`: \n- `dupSign_end`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/ Hide debug error messages\n```python\n# /path/to/file.json: {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}\n\nimport json_duplicate_keys as jdks\n\nJfilepath = \"/path/to/file.json\"\n\nJDKSObject = jdks.load(Jfilepath)\n\nprint(JDKSObject)\n# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>\n```\n---\n\n### JSON_DUPLICATE_KEYS.getObject()\n_Get the JSON object_\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n```\n---\n\n### JSON_DUPLICATE_KEYS.get(`name`, `case_insensitive`=False, `separator`=\"||\", `parse_index`=\"$\", `_isDebug_`=False)\n_Get value in the JSON object by `name`_\n- `name`: the key name of the JSON object. Supported flatten key name format\n- `case_insensitive`: the key name case (in)sensitive\n- `separator`: \n- `parse_index`:\n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.get(\"version{{{_2_}}}\"))\n# OUTPUT: latest\n\nprint(JDKSObject.get(\"release||$0$\"))\n# OUTPUT: {'version': 'latest'}\n\nprint(JDKSObject.get(\"snapshot||author\"))\n# OUTPUT: truocphan\n```\n---\n\n### JSON_DUPLICATE_KEYS.set(`name`, `value`, `case_insensitive`=False, `separator`=\"||\", `parse_index`=\"$\", `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `ordered_dict`=False, `_isDebug_`=False)\n_Set a new `name` and `value` for the JSON object_\n- `name`: new key name for the JSON object. Supported flat key name format\n- `value`: value for key `name`\n- `case_insensitive`: the key name case (in)sensitive\n- `separator`: \n- `parse_index`: \n- `dupSign_start`: \n- `dupSign_end`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{}'\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {}\n\nJDKSObject.set(\"author\", \"truocphan\")\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan'}\n\nJDKSObject.set(\"version\", \"22.3.3\")\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}\n\nJDKSObject.set(\"version\", \"latest\")\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}\n\nJDKSObject.set(\"release\", [{\"version\": \"latest\"}])\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}\n\nJDKSObject.set(\"snapshot\", {})\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}\n\nJDKSObject.set(\"snapshot||author\", \"truocphan\")\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}\n\n\nJstr = '[]'\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: []\n\nJDKSObject.set(\"author\", \"truocphan\")\nprint(JDKSObject.getObject())\n# OUTPUT: [{'author': 'truocphan'}]\n\nJDKSObject.set(\"release\", [])\nprint(JDKSObject.getObject())\n# OUTPUT: [{'author': 'truocphan'}, {'release': []}]\n\nJDKSObject.set(\"$1$||release||\", {\"version\": \"latest\"})\nprint(JDKSObject.getObject())\n# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]\n```\n---\n\n### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `allow_new_key`=False, `separator`=\"||\", `parse_index`=\"$\", `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `ordered_dict`=False, `_isDebug_`=False)\n_Update new `value` for existing `name` or Set a new `name` in the JSON object_\n- `name`: the key name of the JSON object. Supported flatten key name format\n- `value`: new value for key `name`\n- `case_insensitive`: the key name case (in)sensitive\n- `allow_new_key`: allows to create a new key name if the key name does not exist\n- `separator`: \n- `parse_index`: \n- `dupSign_start`: \n- `dupSign_end`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n\nJDKSObject.update(\"version{{{_2_}}}\", [\"22.3.3\", \"latest\"])\nJDKSObject.update(\"snapshot||version\", \"latest\")\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}\n```\n---\n\n### JSON_DUPLICATE_KEYS.delete(`name`, `case_insensitive`=False, `separator`=\"||\", `parse_index`=\"$\", `_isDebug_`=False)\n_Delete a key-value pair in a JSON object by key `name`_\n- `name`: the key name of the JSON object. Supported flatten key name format\n- `case_insensitive`: the key name case (in)sensitive\n- `separator`: \n- `parse_index`: \n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n\nJDKSObject.delete(\"version\")\nJDKSObject.delete(\"release||$0$\")\nJDKSObject.delete(\"snapshot\")\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}\n```\n---\n\n### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`=\"||\", `parse_index`=\"$\", `ordered_dict`=False)\n\n- `name`:\n- `separator`:\n- `parse_index`:\n- `ordered_dict`: preserves the order in which the Keys are inserted\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.filter_keys(\"version\").dumps())\n# OUTPUT: {\"version\": \"22.3.3\", \"version\": \"latest\", \"release||$0$||version\": \"latest\", \"snapshot||version\": \"22.3.3\", \"snapshot||release||$0$||version\": \"latest\"}\n\nprint(JDKSObject.dumps())\n# OUTPUT: {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}\n```\n---\n\n### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`=\"||\", `parse_index`=\"$\", `ordered_dict`=False)\n\n- `value`:\n- `separator`:\n- `parse_index`:\n- `ordered_dict`: preserves the order in which the Keys are inserted\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.filter_values(\"latest\").dumps())\n# OUTPUT: {\"version\": \"latest\", \"release||$0$||version\": \"latest\", \"snapshot||release||$0$||version\": \"latest\"}\n\nprint(JDKSObject.dumps())\n# OUTPUT: {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}\n```\n---\n\n### JSON_DUPLICATE_KEYS.dumps(`dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `_isDebug_`=False, `skipkeys`=False, `ensure_ascii`=True, `check_circular`=True, `allow_nan`=True, `cls`=None, `indent`=None, `separators`=None, `default`=None, `sort_keys`=False)\n_Serialize a JSON object to a JSON format string_\n- `dupSign_start`: \n- `dupSign_end`: \n- `_isDebug_`: Show/ Hide debug error messages\n- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n\nJDKSObject.delete(\"version\")\nJDKSObject.delete(\"release||$0$\")\nJDKSObject.delete(\"snapshot\")\n\nprint(JDKSObject.dumps())\n# OUTPUT: {\"author\": \"truocphan\", \"version\": \"latest\", \"release\": []}\n```\n---\n\n### JSON_DUPLICATE_KEYS.dump(`Jfilepath`, `dupSign_start`=\"{{{\", `dupSign_end`=\"}}}\", `_isDebug_`=False, `skipkeys`=False, `ensure_ascii`=True, `check_circular`=True, `allow_nan`=True, `cls`=None, `indent`=None, `separators`=None, `default`=None, `sort_keys`=False)\n_Serialize a JSON object to a JSON format string and write to a file_\n- `Jfilepath`: the path to the file to save the JSON format string\n- `dupSign_start`: \n- `dupSign_end`: \n- `_isDebug_`: Show/ Hide debug error messages\n- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n\nJDKSObject.delete(\"version\")\nJDKSObject.delete(\"release||$0$\")\nJDKSObject.delete(\"snapshot\")\n\nJfilepath = \"/path/to/file.json\"\nJDKSObject.dump(Jfilepath)\n\nJDKSObject_load = jdks.load(Jfilepath)\nprint(JDKSObject_load.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}\n```\n---\n\n### JSON_DUPLICATE_KEYS.flatten(`separator`=\"||\", `parse_index`=\"$\", `ordered_dict`=False, `_isDebug_`=False)\n_Flatten a JSON object to a single key-value pairs_\n- `separator`: \n- `parse_index`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release\": [{\"version\": \"latest\"}], \"snapshot\": {\"author\": \"truocphan\", \"version\": \"22.3.3\", \"release\": [{\"version\": \"latest\"}]}}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n\nJDKSObject.flatten()\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}\n```\n---\n\n### JSON_DUPLICATE_KEYS.unflatten(`separator`=\"||\", `parse_index`=\"$\", `ordered_dict`=False, `_isDebug_`=False)\n_Unflatten a flattened JSON object back to a JSON object_\n- `separator`: \n- `parse_index`: \n- `ordered_dict`: preserves the order in which the Keys are inserted\n- `_isDebug_`: Show/ Hide debug error messages\n```python\nimport json_duplicate_keys as jdks\n\nJstr = '{\"author\": \"truocphan\", \"version\": \"22.3.3\", \"version\": \"latest\", \"release||$0$||version\": \"latest\", \"snapshot||author\": \"truocphan\", \"snapshot||version\": \"22.3.3\", \"snapshot||release||$0$||version\": \"latest\"}'\n\nJDKSObject = jdks.loads(Jstr)\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}\n\nJDKSObject.unflatten()\n\nprint(JDKSObject.getObject())\n# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}\n```\n---\n\n## CHANGELOG\n#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)\n- **Fixed**: Add subkey name to empty dict of existing key name\n\n#### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)\n- **Updated**: Allows getting (`JSON_DUPLICATE_KEYS.get`), setting (`JSON_DUPLICATE_KEYS.set`), updating (`JSON_DUPLICATE_KEYS.update`), deleting (`JSON_DUPLICATE_KEYS.delete`) JSON_DUPLICATE_KEYS objects with case-insensitive key names\n\n#### [json-duplicate-keys v2024.7.17](https://github.com/truocphan/json-duplicate-keys/tree/2024.7.17)\n- **Fixed**: issue [#3](https://github.com/truocphan/json-duplicate-keys/issues/3) break the set function when the key's value is empty. Thanks [ptth222](https://github.com/ptth222) for reporting this issue.\n\n#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)\n- **New**: _filter_values_\n- **Updated**: _filter_keys_\n\n#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)\n- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_\n---\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys",
"version": "2024.11.28",
"project_urls": {
"Homepage": "https://github.com/truocphan/json-duplicate-keys"
},
"split_keywords": [
"tpcybersec",
" json",
" duplicate keys",
" json duplicate keys",
" flatten",
" unflatten"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "624b057eb8cd4ef7a27ae789bdcc10bfb2127da892928e780f15e95ce358a430",
"md5": "f8b1e8e3ac96b538aebe0a5a6fac7c54",
"sha256": "7ac801c407ed228614d1b467a979a3c7fe38344e1bf293d1a72be5bbede7e218"
},
"downloads": -1,
"filename": "json_duplicate_keys-2024.11.28-py2-none-any.whl",
"has_sig": false,
"md5_digest": "f8b1e8e3ac96b538aebe0a5a6fac7c54",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 8103,
"upload_time": "2024-11-28T02:57:18",
"upload_time_iso_8601": "2024-11-28T02:57:18.655499Z",
"url": "https://files.pythonhosted.org/packages/62/4b/057eb8cd4ef7a27ae789bdcc10bfb2127da892928e780f15e95ce358a430/json_duplicate_keys-2024.11.28-py2-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "83abef8a512fa53b02a2b1f309ddd7e98c191285ba1f4cd417047745a12400f0",
"md5": "489813b6eeeb88b9463c83522d4a0b1b",
"sha256": "4fbfb583e046901272aee4fd9c33eda702e68da65f07bd12c148b81474de1d17"
},
"downloads": -1,
"filename": "json_duplicate_keys-2024.11.28-py3-none-any.whl",
"has_sig": false,
"md5_digest": "489813b6eeeb88b9463c83522d4a0b1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8126,
"upload_time": "2024-11-28T02:57:21",
"upload_time_iso_8601": "2024-11-28T02:57:21.006812Z",
"url": "https://files.pythonhosted.org/packages/83/ab/ef8a512fa53b02a2b1f309ddd7e98c191285ba1f4cd417047745a12400f0/json_duplicate_keys-2024.11.28-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e0ddc8786d1f1d6ad8c42dd51d365e5717a201c00f3531a479b6b23b0ee2c8f3",
"md5": "6c3f1261af4aafd4fb9ea23fcb1d6982",
"sha256": "91d85679e81569669b882925e9a60a8c9d7e4443d04131972f2068a2051eb8e6"
},
"downloads": -1,
"filename": "json_duplicate_keys-2024.11.28.tar.gz",
"has_sig": false,
"md5_digest": "6c3f1261af4aafd4fb9ea23fcb1d6982",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10313,
"upload_time": "2024-11-28T02:57:23",
"upload_time_iso_8601": "2024-11-28T02:57:23.287194Z",
"url": "https://files.pythonhosted.org/packages/e0/dd/c8786d1f1d6ad8c42dd51d365e5717a201c00f3531a479b6b23b0ee2c8f3/json_duplicate_keys-2024.11.28.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-28 02:57:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "truocphan",
"github_project": "json-duplicate-keys",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "json-duplicate-keys"
}