json-duplicate-keys 2024.2.21__tar.gz → 2024.4.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- json-duplicate-keys-2024.4.20/LICENSE +21 -0
- json-duplicate-keys-2024.4.20/MANIFEST.in +1 -0
- {json-duplicate-keys-2024.2.21 → json-duplicate-keys-2024.4.20}/PKG-INFO +38 -8
- json-duplicate-keys-2024.4.20/README.md +389 -0
- {json-duplicate-keys-2024.2.21 → json-duplicate-keys-2024.4.20}/json_duplicate_keys/__init__.py +55 -27
- json-duplicate-keys-2024.4.20/json_duplicate_keys.egg-info/PKG-INFO +403 -0
- json-duplicate-keys-2024.4.20/json_duplicate_keys.egg-info/SOURCES.txt +10 -0
- json-duplicate-keys-2024.4.20/json_duplicate_keys.egg-info/dependency_links.txt +1 -0
- json-duplicate-keys-2024.4.20/json_duplicate_keys.egg-info/top_level.txt +1 -0
- json-duplicate-keys-2024.4.20/setup.cfg +4 -0
- {json-duplicate-keys-2024.2.21 → json-duplicate-keys-2024.4.20}/setup.py +1 -1
- {json-duplicate-keys-2024.2.21 → json-duplicate-keys-2024.4.20}/requirements.txt +0 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 TP Cyber Security
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
include requirements.txt
|
@@ -1,21 +1,21 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version: 2024.
|
3
|
+
Version: 2024.4.20
|
4
4
|
Summary: Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
5
5
|
Home-page: https://github.com/truocphan/json-duplicate-keys
|
6
6
|
Author: TP Cyber Security
|
7
7
|
Author-email: tpcybersec2023@gmail.com
|
8
8
|
License: MIT
|
9
|
-
Description: # JSON Duplicate Keys
|
9
|
+
Description: # JSON Duplicate Keys - PyPI
|
10
10
|
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
11
11
|
|
12
12
|
<p align="center">
|
13
|
-
<a href="https://github.com/truocphan/
|
14
|
-
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/
|
15
|
-
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/
|
16
|
-
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/
|
17
|
-
<a href="https://github.com/truocphan/
|
18
|
-
<a href="https://github.com/truocphan/
|
13
|
+
<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>
|
14
|
+
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
15
|
+
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
16
|
+
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
17
|
+
<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>
|
18
|
+
<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>
|
19
19
|
<a href="https://pypi.org/project/json-duplicate-keys/" target="_blank"><img src="https://img.shields.io/badge/pypi-3775A9?style=for-the-badge&logo=pypi&logoColor=white" height=30></a>
|
20
20
|
<a href="https://www.facebook.com/61550595106970" target="_blank"><img src="https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white" height=30></a>
|
21
21
|
<a href="https://twitter.com/TPCyberSec" target="_blank"><img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" height=30></a>
|
@@ -265,6 +265,27 @@ Description: # JSON Duplicate Keys
|
|
265
265
|
```
|
266
266
|
---
|
267
267
|
|
268
|
+
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
269
|
+
|
270
|
+
- `value`:
|
271
|
+
- `separator`:
|
272
|
+
- `parse_index`:
|
273
|
+
- `ordered_dict`:
|
274
|
+
```python
|
275
|
+
import json_duplicate_keys as jdks
|
276
|
+
|
277
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
278
|
+
|
279
|
+
JDKSObject = jdks.loads(Jstr)
|
280
|
+
|
281
|
+
print(JDKSObject.filter_values("latest").dumps())
|
282
|
+
# OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
|
283
|
+
|
284
|
+
print(JDKSObject.dumps())
|
285
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
286
|
+
```
|
287
|
+
---
|
288
|
+
|
268
289
|
### 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)
|
269
290
|
_Serialize a JSON object to a JSON format string_
|
270
291
|
- `dupSign_start`:
|
@@ -364,6 +385,15 @@ Description: # JSON Duplicate Keys
|
|
364
385
|
print(JDKSObject.getObject())
|
365
386
|
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
366
387
|
```
|
388
|
+
---
|
389
|
+
|
390
|
+
## CHANGELOG
|
391
|
+
#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
|
392
|
+
- **New**: _filter_values_
|
393
|
+
- **Updated**: _filter_keys_
|
394
|
+
|
395
|
+
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
|
396
|
+
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
|
367
397
|
---
|
368
398
|
Keywords: TPCyberSec,json,duplicate keys,json duplicate keys,flatten,unflatten
|
369
399
|
Platform: UNKNOWN
|
@@ -0,0 +1,389 @@
|
|
1
|
+
# JSON Duplicate Keys - PyPI
|
2
|
+
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
<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>
|
6
|
+
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
7
|
+
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
8
|
+
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
9
|
+
<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>
|
10
|
+
<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>
|
11
|
+
<a href="https://pypi.org/project/json-duplicate-keys/" target="_blank"><img src="https://img.shields.io/badge/pypi-3775A9?style=for-the-badge&logo=pypi&logoColor=white" height=30></a>
|
12
|
+
<a href="https://www.facebook.com/61550595106970" target="_blank"><img src="https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white" height=30></a>
|
13
|
+
<a href="https://twitter.com/TPCyberSec" target="_blank"><img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" height=30></a>
|
14
|
+
<a href="https://github.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white" height=30></a>
|
15
|
+
<a href="mailto:tpcybersec2023@gmail.com" target="_blank"><img src="https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white" height=30></a>
|
16
|
+
<a href="https://www.buymeacoffee.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black" height=30></a>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
#### From PyPI:
|
21
|
+
```console
|
22
|
+
pip install json-duplicate-keys
|
23
|
+
```
|
24
|
+
#### From Source:
|
25
|
+
```console
|
26
|
+
git clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>
|
27
|
+
cd json-duplicate-keys
|
28
|
+
python setup.py build
|
29
|
+
python setup.py install
|
30
|
+
```
|
31
|
+
|
32
|
+
## Basic Usage
|
33
|
+
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
34
|
+
_Normalize Key name_
|
35
|
+
- `name`: key name
|
36
|
+
- `dupSign_start`:
|
37
|
+
- `dupSign_end`:
|
38
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
39
|
+
```python
|
40
|
+
import json_duplicate_keys as jdks
|
41
|
+
|
42
|
+
print(jdks.normalize_key("version{{{_2_}}}"))
|
43
|
+
# OUTPUT: version
|
44
|
+
```
|
45
|
+
---
|
46
|
+
|
47
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
48
|
+
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
49
|
+
- `Jstr`: a JSON format string
|
50
|
+
- `dupSign_start`:
|
51
|
+
- `dupSign_end`:
|
52
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
53
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
54
|
+
```python
|
55
|
+
import json_duplicate_keys as jdks
|
56
|
+
|
57
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
58
|
+
|
59
|
+
JDKSObject = jdks.loads(Jstr)
|
60
|
+
|
61
|
+
print(JDKSObject)
|
62
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>
|
63
|
+
```
|
64
|
+
---
|
65
|
+
|
66
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
67
|
+
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
68
|
+
- `Jfilepath`: The path to the file containing the JSON format string
|
69
|
+
- `dupSign_start`:
|
70
|
+
- `dupSign_end`:
|
71
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
72
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
73
|
+
```python
|
74
|
+
# /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"}]}}
|
75
|
+
|
76
|
+
import json_duplicate_keys as jdks
|
77
|
+
|
78
|
+
Jfilepath = "/path/to/file.json"
|
79
|
+
|
80
|
+
JDKSObject = jdks.load(Jfilepath)
|
81
|
+
|
82
|
+
print(JDKSObject)
|
83
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>
|
84
|
+
```
|
85
|
+
---
|
86
|
+
|
87
|
+
### JSON_DUPLICATE_KEYS.getObject()
|
88
|
+
_Get the JSON object_
|
89
|
+
```python
|
90
|
+
import json_duplicate_keys as jdks
|
91
|
+
|
92
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
93
|
+
|
94
|
+
JDKSObject = jdks.loads(Jstr)
|
95
|
+
|
96
|
+
print(JDKSObject.getObject())
|
97
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
98
|
+
```
|
99
|
+
---
|
100
|
+
|
101
|
+
### JSON_DUPLICATE_KEYS.get(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
102
|
+
_Get value in the JSON object by `name`_
|
103
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
104
|
+
- `separator`:
|
105
|
+
- `parse_index`:
|
106
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
107
|
+
```python
|
108
|
+
import json_duplicate_keys as jdks
|
109
|
+
|
110
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
111
|
+
|
112
|
+
JDKSObject = jdks.loads(Jstr)
|
113
|
+
|
114
|
+
print(JDKSObject.get("version{{{_2_}}}"))
|
115
|
+
# OUTPUT: latest
|
116
|
+
|
117
|
+
print(JDKSObject.get("release||$0$"))
|
118
|
+
# OUTPUT: {'version': 'latest'}
|
119
|
+
|
120
|
+
print(JDKSObject.get("snapshot||author"))
|
121
|
+
# OUTPUT: truocphan
|
122
|
+
```
|
123
|
+
---
|
124
|
+
|
125
|
+
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
126
|
+
_Set a new `name` and `value` for the JSON object_
|
127
|
+
- `name`: new key name for the JSON object. Supported flat key name format
|
128
|
+
- `value`: value for key `name`
|
129
|
+
- `separator`:
|
130
|
+
- `parse_index`:
|
131
|
+
- `dupSign_start`:
|
132
|
+
- `dupSign_end`:
|
133
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
134
|
+
- `_isDebug_`: Show/Hide debug error messages
|
135
|
+
```python
|
136
|
+
import json_duplicate_keys as jdks
|
137
|
+
|
138
|
+
Jstr = '{}'
|
139
|
+
JDKSObject = jdks.loads(Jstr)
|
140
|
+
|
141
|
+
print(JDKSObject.getObject())
|
142
|
+
# OUTPUT: {}
|
143
|
+
|
144
|
+
JDKSObject.set("author", "truocphan")
|
145
|
+
print(JDKSObject.getObject())
|
146
|
+
# OUTPUT: {'author': 'truocphan'}
|
147
|
+
|
148
|
+
JDKSObject.set("version", "22.3.3")
|
149
|
+
print(JDKSObject.getObject())
|
150
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}
|
151
|
+
|
152
|
+
JDKSObject.set("version", "latest")
|
153
|
+
print(JDKSObject.getObject())
|
154
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}
|
155
|
+
|
156
|
+
JDKSObject.set("release", [{"version": "latest"}])
|
157
|
+
print(JDKSObject.getObject())
|
158
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}
|
159
|
+
|
160
|
+
JDKSObject.set("snapshot", {})
|
161
|
+
print(JDKSObject.getObject())
|
162
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}
|
163
|
+
|
164
|
+
JDKSObject.set("snapshot||author", "truocphan")
|
165
|
+
print(JDKSObject.getObject())
|
166
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
167
|
+
|
168
|
+
|
169
|
+
Jstr = '[]'
|
170
|
+
JDKSObject = jdks.loads(Jstr)
|
171
|
+
|
172
|
+
print(JDKSObject.getObject())
|
173
|
+
# OUTPUT: []
|
174
|
+
|
175
|
+
JDKSObject.set("author", "truocphan")
|
176
|
+
print(JDKSObject.getObject())
|
177
|
+
# OUTPUT: [{'author': 'truocphan'}]
|
178
|
+
|
179
|
+
JDKSObject.set("release", [])
|
180
|
+
print(JDKSObject.getObject())
|
181
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
182
|
+
|
183
|
+
JDKSObject.set("$1$||release||", {"version": "latest"})
|
184
|
+
print(JDKSObject.getObject())
|
185
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
186
|
+
```
|
187
|
+
---
|
188
|
+
|
189
|
+
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
190
|
+
_Update new `value` for existing `name` in the JSON object_
|
191
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
192
|
+
- `value`: new value for key `name`
|
193
|
+
- `separator`:
|
194
|
+
- `parse_index`:
|
195
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
196
|
+
```python
|
197
|
+
import json_duplicate_keys as jdks
|
198
|
+
|
199
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
200
|
+
|
201
|
+
JDKSObject = jdks.loads(Jstr)
|
202
|
+
|
203
|
+
print(JDKSObject.getObject())
|
204
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
205
|
+
|
206
|
+
JDKSObject.update("version{{{_2_}}}", ["22.3.3", "latest"])
|
207
|
+
JDKSObject.update("snapshot||version", "latest")
|
208
|
+
|
209
|
+
print(JDKSObject.getObject())
|
210
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}
|
211
|
+
```
|
212
|
+
---
|
213
|
+
|
214
|
+
### JSON_DUPLICATE_KEYS.delete(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
215
|
+
_Delete a key-value pair in a JSON object by key `name`_
|
216
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
217
|
+
- `separator`:
|
218
|
+
- `parse_index`:
|
219
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
220
|
+
```python
|
221
|
+
import json_duplicate_keys as jdks
|
222
|
+
|
223
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
224
|
+
|
225
|
+
JDKSObject = jdks.loads(Jstr)
|
226
|
+
|
227
|
+
print(JDKSObject.getObject())
|
228
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
229
|
+
|
230
|
+
JDKSObject.delete("version")
|
231
|
+
JDKSObject.delete("release||$0$")
|
232
|
+
JDKSObject.delete("snapshot")
|
233
|
+
|
234
|
+
print(JDKSObject.getObject())
|
235
|
+
# OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}
|
236
|
+
```
|
237
|
+
---
|
238
|
+
|
239
|
+
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
240
|
+
|
241
|
+
- `name`:
|
242
|
+
- `separator`:
|
243
|
+
- `parse_index`:
|
244
|
+
- `ordered_dict`:
|
245
|
+
```python
|
246
|
+
import json_duplicate_keys as jdks
|
247
|
+
|
248
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
249
|
+
|
250
|
+
JDKSObject = jdks.loads(Jstr)
|
251
|
+
|
252
|
+
print(JDKSObject.filter_keys("version").dumps())
|
253
|
+
# OUTPUT: {"version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}
|
254
|
+
|
255
|
+
print(JDKSObject.dumps())
|
256
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
257
|
+
```
|
258
|
+
---
|
259
|
+
|
260
|
+
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
261
|
+
|
262
|
+
- `value`:
|
263
|
+
- `separator`:
|
264
|
+
- `parse_index`:
|
265
|
+
- `ordered_dict`:
|
266
|
+
```python
|
267
|
+
import json_duplicate_keys as jdks
|
268
|
+
|
269
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
270
|
+
|
271
|
+
JDKSObject = jdks.loads(Jstr)
|
272
|
+
|
273
|
+
print(JDKSObject.filter_values("latest").dumps())
|
274
|
+
# OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
|
275
|
+
|
276
|
+
print(JDKSObject.dumps())
|
277
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
278
|
+
```
|
279
|
+
---
|
280
|
+
|
281
|
+
### 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)
|
282
|
+
_Serialize a JSON object to a JSON format string_
|
283
|
+
- `dupSign_start`:
|
284
|
+
- `dupSign_end`:
|
285
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
286
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
287
|
+
```python
|
288
|
+
import json_duplicate_keys as jdks
|
289
|
+
|
290
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
291
|
+
|
292
|
+
JDKSObject = jdks.loads(Jstr)
|
293
|
+
|
294
|
+
print(JDKSObject.getObject())
|
295
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
296
|
+
|
297
|
+
JDKSObject.delete("version")
|
298
|
+
JDKSObject.delete("release||$0$")
|
299
|
+
JDKSObject.delete("snapshot")
|
300
|
+
|
301
|
+
print(JDKSObject.dumps())
|
302
|
+
# OUTPUT: {"author": "truocphan", "version": "latest", "release": []}
|
303
|
+
```
|
304
|
+
---
|
305
|
+
|
306
|
+
### 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)
|
307
|
+
_Serialize a JSON object to a JSON format string and write to a file_
|
308
|
+
- `Jfilepath`: the path to the file to save the JSON format string
|
309
|
+
- `dupSign_start`:
|
310
|
+
- `dupSign_end`:
|
311
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
312
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
313
|
+
```python
|
314
|
+
import json_duplicate_keys as jdks
|
315
|
+
|
316
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
317
|
+
|
318
|
+
JDKSObject = jdks.loads(Jstr)
|
319
|
+
|
320
|
+
print(JDKSObject.getObject())
|
321
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
322
|
+
|
323
|
+
JDKSObject.delete("version")
|
324
|
+
JDKSObject.delete("release||$0$")
|
325
|
+
JDKSObject.delete("snapshot")
|
326
|
+
|
327
|
+
Jfilepath = "/path/to/file.json"
|
328
|
+
JDKSObject.dump(Jfilepath)
|
329
|
+
|
330
|
+
JDKSObject_load = jdks.load(Jfilepath)
|
331
|
+
print(JDKSObject_load.getObject())
|
332
|
+
# OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}
|
333
|
+
```
|
334
|
+
---
|
335
|
+
|
336
|
+
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
337
|
+
_Flatten a JSON object to a single key-value pairs_
|
338
|
+
- `separator`:
|
339
|
+
- `parse_index`:
|
340
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
341
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
342
|
+
```python
|
343
|
+
import json_duplicate_keys as jdks
|
344
|
+
|
345
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
346
|
+
|
347
|
+
JDKSObject = jdks.loads(Jstr)
|
348
|
+
|
349
|
+
print(JDKSObject.getObject())
|
350
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
351
|
+
|
352
|
+
JDKSObject.flatten()
|
353
|
+
|
354
|
+
print(JDKSObject.getObject())
|
355
|
+
# 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'}
|
356
|
+
```
|
357
|
+
---
|
358
|
+
|
359
|
+
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
360
|
+
_Unflatten a flattened JSON object back to a JSON object_
|
361
|
+
- `separator`:
|
362
|
+
- `parse_index`:
|
363
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
364
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
365
|
+
```python
|
366
|
+
import json_duplicate_keys as jdks
|
367
|
+
|
368
|
+
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"}'
|
369
|
+
|
370
|
+
JDKSObject = jdks.loads(Jstr)
|
371
|
+
|
372
|
+
print(JDKSObject.getObject())
|
373
|
+
# 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'}
|
374
|
+
|
375
|
+
JDKSObject.unflatten()
|
376
|
+
|
377
|
+
print(JDKSObject.getObject())
|
378
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
379
|
+
```
|
380
|
+
---
|
381
|
+
|
382
|
+
## CHANGELOG
|
383
|
+
#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
|
384
|
+
- **New**: _filter_values_
|
385
|
+
- **Updated**: _filter_keys_
|
386
|
+
|
387
|
+
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
|
388
|
+
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
|
389
|
+
---
|
{json-duplicate-keys-2024.2.21 → json-duplicate-keys-2024.4.20}/json_duplicate_keys/__init__.py
RENAMED
@@ -8,14 +8,12 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
|
|
8
8
|
if type(_isDebug_) != bool: _isDebug_ = False
|
9
9
|
try:
|
10
10
|
if type(name) not in [str, unicode]:
|
11
|
-
|
12
|
-
exit()
|
11
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
13
12
|
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
|
14
13
|
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
|
15
14
|
except Exception as e:
|
16
15
|
if type(name) not in [str]:
|
17
|
-
|
18
|
-
exit()
|
16
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
19
17
|
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
|
20
18
|
if type(dupSign_end) not in [str]: dupSign_end = "}}}"
|
21
19
|
|
@@ -37,14 +35,12 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
|
|
37
35
|
if type(ordered_dict) != bool: ordered_dict = False
|
38
36
|
try:
|
39
37
|
if type(Jstr) not in [str, unicode]:
|
40
|
-
|
41
|
-
exit()
|
38
|
+
exit("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
|
42
39
|
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
|
43
40
|
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
|
44
41
|
except Exception as e:
|
45
42
|
if type(Jstr) not in [str]:
|
46
|
-
|
47
|
-
exit()
|
43
|
+
exit("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
|
48
44
|
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
|
49
45
|
if type(dupSign_end) not in [str]: dupSign_end = "}}}"
|
50
46
|
|
@@ -195,14 +191,12 @@ class JSON_DUPLICATE_KEYS:
|
|
195
191
|
if type(_isDebug_) != bool: _isDebug_ = False
|
196
192
|
try:
|
197
193
|
if type(name) not in [str, unicode]:
|
198
|
-
|
199
|
-
exit()
|
194
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
200
195
|
if type(separator) not in [str, unicode]: separator = "||"
|
201
196
|
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
202
197
|
except Exception as e:
|
203
198
|
if type(name) not in [str]:
|
204
|
-
|
205
|
-
exit()
|
199
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
206
200
|
if type(separator) not in [str]: separator = "||"
|
207
201
|
if type(parse_index) not in [str]: parse_index = "$"
|
208
202
|
|
@@ -246,16 +240,14 @@ class JSON_DUPLICATE_KEYS:
|
|
246
240
|
if type(ordered_dict) != bool: ordered_dict = False
|
247
241
|
try:
|
248
242
|
if type(name) not in [str, unicode]:
|
249
|
-
|
250
|
-
exit()
|
243
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
251
244
|
if type(separator) not in [str, unicode]: separator = "||"
|
252
245
|
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
253
246
|
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
|
254
247
|
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
|
255
248
|
except Exception as e:
|
256
249
|
if type(name) not in [str]:
|
257
|
-
|
258
|
-
exit()
|
250
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
259
251
|
if type(separator) not in [str]: separator = "||"
|
260
252
|
if type(parse_index) not in [str]: parse_index = "$"
|
261
253
|
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
|
@@ -308,6 +300,7 @@ class JSON_DUPLICATE_KEYS:
|
|
308
300
|
exec_expression += "["+repr(k)+"]"
|
309
301
|
|
310
302
|
exec(exec_expression+"="+repr(value))
|
303
|
+
return True
|
311
304
|
# Add new key
|
312
305
|
elif self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index) != "JSON_DUPLICATE_KEYS_ERROR":
|
313
306
|
if type(self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index)) == list:
|
@@ -331,6 +324,7 @@ class JSON_DUPLICATE_KEYS:
|
|
331
324
|
exec_expression += "["+repr(k)+"]"
|
332
325
|
|
333
326
|
exec(exec_expression+".append({"+repr(name_split_lastKey)+":"+repr(value)+"})")
|
327
|
+
return True
|
334
328
|
elif type(self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index)) == dict:
|
335
329
|
exec_expression = "self.getObject()"
|
336
330
|
|
@@ -341,6 +335,7 @@ class JSON_DUPLICATE_KEYS:
|
|
341
335
|
exec_expression += "["+repr(k)+"]"
|
342
336
|
|
343
337
|
exec(exec_expression+"["+repr(name_split_lastKey)+"]="+repr(value))
|
338
|
+
return True
|
344
339
|
else:
|
345
340
|
if _isDebug_: print("\x1b[31m[-] KeyNameNotExistError: {}\x1b[0m".format(separator.join(name_split_first)))
|
346
341
|
# Add new key
|
@@ -352,6 +347,7 @@ class JSON_DUPLICATE_KEYS:
|
|
352
347
|
self.__Jobj.append({name_split_lastKey: value})
|
353
348
|
else:
|
354
349
|
self.__Jobj[name_split_lastKey] = value
|
350
|
+
return True
|
355
351
|
else:
|
356
352
|
if _isDebug_: print("\x1b[31m[-] KeyNameInvalidError: {}\x1b[0m".format(separator.join(name_split_first)))
|
357
353
|
else:
|
@@ -360,6 +356,8 @@ class JSON_DUPLICATE_KEYS:
|
|
360
356
|
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
|
361
357
|
else:
|
362
358
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be list, dict or OrderedDict, not {}\x1b[0m".format(type(self.getObject())))
|
359
|
+
|
360
|
+
return False
|
363
361
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
364
362
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
365
363
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -375,14 +373,12 @@ class JSON_DUPLICATE_KEYS:
|
|
375
373
|
if type(_isDebug_) != bool: _isDebug_ = False
|
376
374
|
try:
|
377
375
|
if type(name) not in [str, unicode]:
|
378
|
-
|
379
|
-
exit()
|
376
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
380
377
|
if type(separator) not in [str, unicode]: separator = "||"
|
381
378
|
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
382
379
|
except Exception as e:
|
383
380
|
if type(name) not in [str]:
|
384
|
-
|
385
|
-
exit()
|
381
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
386
382
|
if type(separator) not in [str]: separator = "||"
|
387
383
|
if type(parse_index) not in [str]: parse_index = "$"
|
388
384
|
|
@@ -397,8 +393,11 @@ class JSON_DUPLICATE_KEYS:
|
|
397
393
|
exec_expression += "["+repr(k)+"]"
|
398
394
|
|
399
395
|
exec(exec_expression+"="+repr(value))
|
396
|
+
return True
|
400
397
|
except Exception as e:
|
401
398
|
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
|
399
|
+
|
400
|
+
return False
|
402
401
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
403
402
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
404
403
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -415,14 +414,12 @@ class JSON_DUPLICATE_KEYS:
|
|
415
414
|
|
416
415
|
try:
|
417
416
|
if type(name) not in [str, unicode]:
|
418
|
-
|
419
|
-
exit()
|
417
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
420
418
|
if type(separator) not in [str, unicode]: separator = "||"
|
421
419
|
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
422
420
|
except Exception as e:
|
423
421
|
if type(name) not in [str]:
|
424
|
-
|
425
|
-
exit()
|
422
|
+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
426
423
|
if type(separator) not in [str]: separator = "||"
|
427
424
|
if type(parse_index) not in [str]: parse_index = "$"
|
428
425
|
|
@@ -437,8 +434,11 @@ class JSON_DUPLICATE_KEYS:
|
|
437
434
|
exec_expression += "["+repr(k)+"]"
|
438
435
|
|
439
436
|
exec(exec_expression)
|
437
|
+
return True
|
440
438
|
except Exception as e:
|
441
439
|
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
|
440
|
+
|
441
|
+
return False
|
442
442
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
443
443
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
444
444
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -454,9 +454,37 @@ class JSON_DUPLICATE_KEYS:
|
|
454
454
|
JDKSObject.flatten(separator=separator, parse_index=parse_index, ordered_dict=ordered_dict)
|
455
455
|
newJDKSObject = loads("{}", ordered_dict=ordered_dict)
|
456
456
|
|
457
|
-
for k in JDKSObject.getObject():
|
458
|
-
if
|
459
|
-
|
457
|
+
for k, v in JDKSObject.getObject().items():
|
458
|
+
if type(k) == str and type(name) == str:
|
459
|
+
if re.search(name, k):
|
460
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
461
|
+
else:
|
462
|
+
if name == k:
|
463
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
464
|
+
|
465
|
+
return newJDKSObject
|
466
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
467
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
468
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
469
|
+
|
470
|
+
|
471
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
472
|
+
# # # # # # # # # # # # filter_values # # # # # # # # # # # # #
|
473
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
474
|
+
def filter_values(self, value, separator="||", parse_index="$", ordered_dict=False):
|
475
|
+
import re, copy
|
476
|
+
|
477
|
+
JDKSObject = copy.deepcopy(self)
|
478
|
+
JDKSObject.flatten(separator=separator, parse_index=parse_index, ordered_dict=ordered_dict)
|
479
|
+
newJDKSObject = loads("{}", ordered_dict=ordered_dict)
|
480
|
+
|
481
|
+
for k, v in JDKSObject.getObject().items():
|
482
|
+
if type(v) == str and type(value) == str:
|
483
|
+
if re.search(value, v):
|
484
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
485
|
+
else:
|
486
|
+
if value == v:
|
487
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
460
488
|
|
461
489
|
return newJDKSObject
|
462
490
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -0,0 +1,403 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: json-duplicate-keys
|
3
|
+
Version: 2024.4.20
|
4
|
+
Summary: Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
5
|
+
Home-page: https://github.com/truocphan/json-duplicate-keys
|
6
|
+
Author: TP Cyber Security
|
7
|
+
Author-email: tpcybersec2023@gmail.com
|
8
|
+
License: MIT
|
9
|
+
Description: # JSON Duplicate Keys - PyPI
|
10
|
+
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
11
|
+
|
12
|
+
<p align="center">
|
13
|
+
<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>
|
14
|
+
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
15
|
+
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
16
|
+
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
17
|
+
<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>
|
18
|
+
<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>
|
19
|
+
<a href="https://pypi.org/project/json-duplicate-keys/" target="_blank"><img src="https://img.shields.io/badge/pypi-3775A9?style=for-the-badge&logo=pypi&logoColor=white" height=30></a>
|
20
|
+
<a href="https://www.facebook.com/61550595106970" target="_blank"><img src="https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white" height=30></a>
|
21
|
+
<a href="https://twitter.com/TPCyberSec" target="_blank"><img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" height=30></a>
|
22
|
+
<a href="https://github.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white" height=30></a>
|
23
|
+
<a href="mailto:tpcybersec2023@gmail.com" target="_blank"><img src="https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white" height=30></a>
|
24
|
+
<a href="https://www.buymeacoffee.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black" height=30></a>
|
25
|
+
</p>
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
#### From PyPI:
|
29
|
+
```console
|
30
|
+
pip install json-duplicate-keys
|
31
|
+
```
|
32
|
+
#### From Source:
|
33
|
+
```console
|
34
|
+
git clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>
|
35
|
+
cd json-duplicate-keys
|
36
|
+
python setup.py build
|
37
|
+
python setup.py install
|
38
|
+
```
|
39
|
+
|
40
|
+
## Basic Usage
|
41
|
+
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
42
|
+
_Normalize Key name_
|
43
|
+
- `name`: key name
|
44
|
+
- `dupSign_start`:
|
45
|
+
- `dupSign_end`:
|
46
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
47
|
+
```python
|
48
|
+
import json_duplicate_keys as jdks
|
49
|
+
|
50
|
+
print(jdks.normalize_key("version{{{_2_}}}"))
|
51
|
+
# OUTPUT: version
|
52
|
+
```
|
53
|
+
---
|
54
|
+
|
55
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
56
|
+
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
57
|
+
- `Jstr`: a JSON format string
|
58
|
+
- `dupSign_start`:
|
59
|
+
- `dupSign_end`:
|
60
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
61
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
62
|
+
```python
|
63
|
+
import json_duplicate_keys as jdks
|
64
|
+
|
65
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
66
|
+
|
67
|
+
JDKSObject = jdks.loads(Jstr)
|
68
|
+
|
69
|
+
print(JDKSObject)
|
70
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>
|
71
|
+
```
|
72
|
+
---
|
73
|
+
|
74
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
75
|
+
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
76
|
+
- `Jfilepath`: The path to the file containing the JSON format string
|
77
|
+
- `dupSign_start`:
|
78
|
+
- `dupSign_end`:
|
79
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
80
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
81
|
+
```python
|
82
|
+
# /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"}]}}
|
83
|
+
|
84
|
+
import json_duplicate_keys as jdks
|
85
|
+
|
86
|
+
Jfilepath = "/path/to/file.json"
|
87
|
+
|
88
|
+
JDKSObject = jdks.load(Jfilepath)
|
89
|
+
|
90
|
+
print(JDKSObject)
|
91
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>
|
92
|
+
```
|
93
|
+
---
|
94
|
+
|
95
|
+
### JSON_DUPLICATE_KEYS.getObject()
|
96
|
+
_Get the JSON object_
|
97
|
+
```python
|
98
|
+
import json_duplicate_keys as jdks
|
99
|
+
|
100
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
101
|
+
|
102
|
+
JDKSObject = jdks.loads(Jstr)
|
103
|
+
|
104
|
+
print(JDKSObject.getObject())
|
105
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
106
|
+
```
|
107
|
+
---
|
108
|
+
|
109
|
+
### JSON_DUPLICATE_KEYS.get(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
110
|
+
_Get value in the JSON object by `name`_
|
111
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
112
|
+
- `separator`:
|
113
|
+
- `parse_index`:
|
114
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
115
|
+
```python
|
116
|
+
import json_duplicate_keys as jdks
|
117
|
+
|
118
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
119
|
+
|
120
|
+
JDKSObject = jdks.loads(Jstr)
|
121
|
+
|
122
|
+
print(JDKSObject.get("version{{{_2_}}}"))
|
123
|
+
# OUTPUT: latest
|
124
|
+
|
125
|
+
print(JDKSObject.get("release||$0$"))
|
126
|
+
# OUTPUT: {'version': 'latest'}
|
127
|
+
|
128
|
+
print(JDKSObject.get("snapshot||author"))
|
129
|
+
# OUTPUT: truocphan
|
130
|
+
```
|
131
|
+
---
|
132
|
+
|
133
|
+
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
134
|
+
_Set a new `name` and `value` for the JSON object_
|
135
|
+
- `name`: new key name for the JSON object. Supported flat key name format
|
136
|
+
- `value`: value for key `name`
|
137
|
+
- `separator`:
|
138
|
+
- `parse_index`:
|
139
|
+
- `dupSign_start`:
|
140
|
+
- `dupSign_end`:
|
141
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
142
|
+
- `_isDebug_`: Show/Hide debug error messages
|
143
|
+
```python
|
144
|
+
import json_duplicate_keys as jdks
|
145
|
+
|
146
|
+
Jstr = '{}'
|
147
|
+
JDKSObject = jdks.loads(Jstr)
|
148
|
+
|
149
|
+
print(JDKSObject.getObject())
|
150
|
+
# OUTPUT: {}
|
151
|
+
|
152
|
+
JDKSObject.set("author", "truocphan")
|
153
|
+
print(JDKSObject.getObject())
|
154
|
+
# OUTPUT: {'author': 'truocphan'}
|
155
|
+
|
156
|
+
JDKSObject.set("version", "22.3.3")
|
157
|
+
print(JDKSObject.getObject())
|
158
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}
|
159
|
+
|
160
|
+
JDKSObject.set("version", "latest")
|
161
|
+
print(JDKSObject.getObject())
|
162
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}
|
163
|
+
|
164
|
+
JDKSObject.set("release", [{"version": "latest"}])
|
165
|
+
print(JDKSObject.getObject())
|
166
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}
|
167
|
+
|
168
|
+
JDKSObject.set("snapshot", {})
|
169
|
+
print(JDKSObject.getObject())
|
170
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}
|
171
|
+
|
172
|
+
JDKSObject.set("snapshot||author", "truocphan")
|
173
|
+
print(JDKSObject.getObject())
|
174
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
175
|
+
|
176
|
+
|
177
|
+
Jstr = '[]'
|
178
|
+
JDKSObject = jdks.loads(Jstr)
|
179
|
+
|
180
|
+
print(JDKSObject.getObject())
|
181
|
+
# OUTPUT: []
|
182
|
+
|
183
|
+
JDKSObject.set("author", "truocphan")
|
184
|
+
print(JDKSObject.getObject())
|
185
|
+
# OUTPUT: [{'author': 'truocphan'}]
|
186
|
+
|
187
|
+
JDKSObject.set("release", [])
|
188
|
+
print(JDKSObject.getObject())
|
189
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
190
|
+
|
191
|
+
JDKSObject.set("$1$||release||", {"version": "latest"})
|
192
|
+
print(JDKSObject.getObject())
|
193
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
194
|
+
```
|
195
|
+
---
|
196
|
+
|
197
|
+
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
198
|
+
_Update new `value` for existing `name` in the JSON object_
|
199
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
200
|
+
- `value`: new value for key `name`
|
201
|
+
- `separator`:
|
202
|
+
- `parse_index`:
|
203
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
204
|
+
```python
|
205
|
+
import json_duplicate_keys as jdks
|
206
|
+
|
207
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
208
|
+
|
209
|
+
JDKSObject = jdks.loads(Jstr)
|
210
|
+
|
211
|
+
print(JDKSObject.getObject())
|
212
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
213
|
+
|
214
|
+
JDKSObject.update("version{{{_2_}}}", ["22.3.3", "latest"])
|
215
|
+
JDKSObject.update("snapshot||version", "latest")
|
216
|
+
|
217
|
+
print(JDKSObject.getObject())
|
218
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}
|
219
|
+
```
|
220
|
+
---
|
221
|
+
|
222
|
+
### JSON_DUPLICATE_KEYS.delete(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
223
|
+
_Delete a key-value pair in a JSON object by key `name`_
|
224
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
225
|
+
- `separator`:
|
226
|
+
- `parse_index`:
|
227
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
228
|
+
```python
|
229
|
+
import json_duplicate_keys as jdks
|
230
|
+
|
231
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
232
|
+
|
233
|
+
JDKSObject = jdks.loads(Jstr)
|
234
|
+
|
235
|
+
print(JDKSObject.getObject())
|
236
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
237
|
+
|
238
|
+
JDKSObject.delete("version")
|
239
|
+
JDKSObject.delete("release||$0$")
|
240
|
+
JDKSObject.delete("snapshot")
|
241
|
+
|
242
|
+
print(JDKSObject.getObject())
|
243
|
+
# OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}
|
244
|
+
```
|
245
|
+
---
|
246
|
+
|
247
|
+
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
248
|
+
|
249
|
+
- `name`:
|
250
|
+
- `separator`:
|
251
|
+
- `parse_index`:
|
252
|
+
- `ordered_dict`:
|
253
|
+
```python
|
254
|
+
import json_duplicate_keys as jdks
|
255
|
+
|
256
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
257
|
+
|
258
|
+
JDKSObject = jdks.loads(Jstr)
|
259
|
+
|
260
|
+
print(JDKSObject.filter_keys("version").dumps())
|
261
|
+
# OUTPUT: {"version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}
|
262
|
+
|
263
|
+
print(JDKSObject.dumps())
|
264
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
265
|
+
```
|
266
|
+
---
|
267
|
+
|
268
|
+
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
269
|
+
|
270
|
+
- `value`:
|
271
|
+
- `separator`:
|
272
|
+
- `parse_index`:
|
273
|
+
- `ordered_dict`:
|
274
|
+
```python
|
275
|
+
import json_duplicate_keys as jdks
|
276
|
+
|
277
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
278
|
+
|
279
|
+
JDKSObject = jdks.loads(Jstr)
|
280
|
+
|
281
|
+
print(JDKSObject.filter_values("latest").dumps())
|
282
|
+
# OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
|
283
|
+
|
284
|
+
print(JDKSObject.dumps())
|
285
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
286
|
+
```
|
287
|
+
---
|
288
|
+
|
289
|
+
### 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)
|
290
|
+
_Serialize a JSON object to a JSON format string_
|
291
|
+
- `dupSign_start`:
|
292
|
+
- `dupSign_end`:
|
293
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
294
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
295
|
+
```python
|
296
|
+
import json_duplicate_keys as jdks
|
297
|
+
|
298
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
299
|
+
|
300
|
+
JDKSObject = jdks.loads(Jstr)
|
301
|
+
|
302
|
+
print(JDKSObject.getObject())
|
303
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
304
|
+
|
305
|
+
JDKSObject.delete("version")
|
306
|
+
JDKSObject.delete("release||$0$")
|
307
|
+
JDKSObject.delete("snapshot")
|
308
|
+
|
309
|
+
print(JDKSObject.dumps())
|
310
|
+
# OUTPUT: {"author": "truocphan", "version": "latest", "release": []}
|
311
|
+
```
|
312
|
+
---
|
313
|
+
|
314
|
+
### 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)
|
315
|
+
_Serialize a JSON object to a JSON format string and write to a file_
|
316
|
+
- `Jfilepath`: the path to the file to save the JSON format string
|
317
|
+
- `dupSign_start`:
|
318
|
+
- `dupSign_end`:
|
319
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
320
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
321
|
+
```python
|
322
|
+
import json_duplicate_keys as jdks
|
323
|
+
|
324
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
325
|
+
|
326
|
+
JDKSObject = jdks.loads(Jstr)
|
327
|
+
|
328
|
+
print(JDKSObject.getObject())
|
329
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
330
|
+
|
331
|
+
JDKSObject.delete("version")
|
332
|
+
JDKSObject.delete("release||$0$")
|
333
|
+
JDKSObject.delete("snapshot")
|
334
|
+
|
335
|
+
Jfilepath = "/path/to/file.json"
|
336
|
+
JDKSObject.dump(Jfilepath)
|
337
|
+
|
338
|
+
JDKSObject_load = jdks.load(Jfilepath)
|
339
|
+
print(JDKSObject_load.getObject())
|
340
|
+
# OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}
|
341
|
+
```
|
342
|
+
---
|
343
|
+
|
344
|
+
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
345
|
+
_Flatten a JSON object to a single key-value pairs_
|
346
|
+
- `separator`:
|
347
|
+
- `parse_index`:
|
348
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
349
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
350
|
+
```python
|
351
|
+
import json_duplicate_keys as jdks
|
352
|
+
|
353
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
354
|
+
|
355
|
+
JDKSObject = jdks.loads(Jstr)
|
356
|
+
|
357
|
+
print(JDKSObject.getObject())
|
358
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
359
|
+
|
360
|
+
JDKSObject.flatten()
|
361
|
+
|
362
|
+
print(JDKSObject.getObject())
|
363
|
+
# 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'}
|
364
|
+
```
|
365
|
+
---
|
366
|
+
|
367
|
+
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
368
|
+
_Unflatten a flattened JSON object back to a JSON object_
|
369
|
+
- `separator`:
|
370
|
+
- `parse_index`:
|
371
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
372
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
373
|
+
```python
|
374
|
+
import json_duplicate_keys as jdks
|
375
|
+
|
376
|
+
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"}'
|
377
|
+
|
378
|
+
JDKSObject = jdks.loads(Jstr)
|
379
|
+
|
380
|
+
print(JDKSObject.getObject())
|
381
|
+
# 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'}
|
382
|
+
|
383
|
+
JDKSObject.unflatten()
|
384
|
+
|
385
|
+
print(JDKSObject.getObject())
|
386
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
387
|
+
```
|
388
|
+
---
|
389
|
+
|
390
|
+
## CHANGELOG
|
391
|
+
#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
|
392
|
+
- **New**: _filter_values_
|
393
|
+
- **Updated**: _filter_keys_
|
394
|
+
|
395
|
+
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
|
396
|
+
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
|
397
|
+
---
|
398
|
+
Keywords: TPCyberSec,json,duplicate keys,json duplicate keys,flatten,unflatten
|
399
|
+
Platform: UNKNOWN
|
400
|
+
Classifier: Programming Language :: Python :: 3
|
401
|
+
Classifier: Programming Language :: Python :: 2
|
402
|
+
Classifier: Programming Language :: Python :: Implementation :: Jython
|
403
|
+
Description-Content-Type: text/markdown
|
@@ -0,0 +1,10 @@
|
|
1
|
+
LICENSE
|
2
|
+
MANIFEST.in
|
3
|
+
README.md
|
4
|
+
requirements.txt
|
5
|
+
setup.py
|
6
|
+
json_duplicate_keys/__init__.py
|
7
|
+
json_duplicate_keys.egg-info/PKG-INFO
|
8
|
+
json_duplicate_keys.egg-info/SOURCES.txt
|
9
|
+
json_duplicate_keys.egg-info/dependency_links.txt
|
10
|
+
json_duplicate_keys.egg-info/top_level.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
json_duplicate_keys
|
File without changes
|