json-duplicate-keys 2024.11.28__tar.gz → 2024.12.12__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.11.28/json_duplicate_keys.egg-info → json_duplicate_keys-2024.12.12}/PKG-INFO +40 -5
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/README.md +39 -4
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/json_duplicate_keys/__init__.py +48 -28
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12/json_duplicate_keys.egg-info}/PKG-INFO +40 -5
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/setup.py +1 -1
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/LICENSE +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/MANIFEST.in +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/json_duplicate_keys.egg-info/SOURCES.txt +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/json_duplicate_keys.egg-info/dependency_links.txt +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/json_duplicate_keys.egg-info/top_level.txt +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/requirements.txt +0 -0
- {json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version: 2024.
|
3
|
+
Version: 2024.12.12
|
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
|
@@ -17,12 +17,15 @@ License-File: LICENSE
|
|
17
17
|
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
18
18
|
|
19
19
|
<p align="center">
|
20
|
-
|
20
|
+
<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>
|
21
21
|
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
22
22
|
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
23
23
|
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
24
24
|
<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>
|
25
25
|
<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>
|
26
|
+
<br>
|
27
|
+
<a href="#"><img src="https://img.shields.io/pypi/v/json-duplicate-keys" height=30></a>
|
28
|
+
<a href="#"><img src="https://img.shields.io/pypi/dm/json-duplicate-keys" height=30></a>
|
26
29
|
</p>
|
27
30
|
|
28
31
|
## Installation
|
@@ -122,13 +125,13 @@ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "relea
|
|
122
125
|
JDKSObject = jdks.loads(Jstr)
|
123
126
|
|
124
127
|
print(JDKSObject.get("version{{{_2_}}}"))
|
125
|
-
# OUTPUT: latest
|
128
|
+
# OUTPUT: {'name': 'version{{{_2_}}}', 'value': 'latest'}
|
126
129
|
|
127
130
|
print(JDKSObject.get("release||$0$"))
|
128
|
-
# OUTPUT: {'version': 'latest'}
|
131
|
+
# OUTPUT: {'name': 'release||$0$', 'value': {'version': 'latest'}}
|
129
132
|
|
130
133
|
print(JDKSObject.get("snapshot||author"))
|
131
|
-
# OUTPUT: truocphan
|
134
|
+
# OUTPUT: {'name': 'snapshot||author', 'value': 'truocphan'}
|
132
135
|
```
|
133
136
|
---
|
134
137
|
|
@@ -197,6 +200,35 @@ print(JDKSObject.getObject())
|
|
197
200
|
```
|
198
201
|
---
|
199
202
|
|
203
|
+
### JSON_DUPLICATE_KEYS.insert(`name`, `value`, `position`=None, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
204
|
+
_Insert `value` at `position` in value list of `name`_
|
205
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
206
|
+
- `value`: new value for key `name`
|
207
|
+
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
208
|
+
- `case_insensitive`: the key name case (in)sensitive
|
209
|
+
- `separator`:
|
210
|
+
- `parse_index`:
|
211
|
+
- `dupSign_start`:
|
212
|
+
- `dupSign_end`:
|
213
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
214
|
+
```python
|
215
|
+
import json_duplicate_keys as jdks
|
216
|
+
|
217
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
218
|
+
|
219
|
+
JDKSObject = jdks.loads(Jstr)
|
220
|
+
|
221
|
+
print(JDKSObject.getObject())
|
222
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
223
|
+
|
224
|
+
JDKSObject.insert("release", {'version': '2025.1.1'})
|
225
|
+
JDKSObject.insert("snapshot||release", {'version': '2025.1.1'}, 0)
|
226
|
+
|
227
|
+
print(JDKSObject.getObject())
|
228
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}, {'version': '2025.1.1'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': '2025.1.1'}, {'version': 'latest'}]}}
|
229
|
+
```
|
230
|
+
---
|
231
|
+
|
200
232
|
### 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)
|
201
233
|
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
202
234
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
@@ -397,6 +429,9 @@ print(JDKSObject.getObject())
|
|
397
429
|
---
|
398
430
|
|
399
431
|
## CHANGELOG
|
432
|
+
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
433
|
+
- **New**: _insert_ function
|
434
|
+
|
400
435
|
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
401
436
|
- **Fixed**: Add subkey name to empty dict of existing key name
|
402
437
|
|
@@ -2,12 +2,15 @@
|
|
2
2
|
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
3
3
|
|
4
4
|
<p align="center">
|
5
|
-
|
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
6
|
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
7
7
|
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
8
8
|
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
9
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
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
|
+
<br>
|
12
|
+
<a href="#"><img src="https://img.shields.io/pypi/v/json-duplicate-keys" height=30></a>
|
13
|
+
<a href="#"><img src="https://img.shields.io/pypi/dm/json-duplicate-keys" height=30></a>
|
11
14
|
</p>
|
12
15
|
|
13
16
|
## Installation
|
@@ -107,13 +110,13 @@ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "relea
|
|
107
110
|
JDKSObject = jdks.loads(Jstr)
|
108
111
|
|
109
112
|
print(JDKSObject.get("version{{{_2_}}}"))
|
110
|
-
# OUTPUT: latest
|
113
|
+
# OUTPUT: {'name': 'version{{{_2_}}}', 'value': 'latest'}
|
111
114
|
|
112
115
|
print(JDKSObject.get("release||$0$"))
|
113
|
-
# OUTPUT: {'version': 'latest'}
|
116
|
+
# OUTPUT: {'name': 'release||$0$', 'value': {'version': 'latest'}}
|
114
117
|
|
115
118
|
print(JDKSObject.get("snapshot||author"))
|
116
|
-
# OUTPUT: truocphan
|
119
|
+
# OUTPUT: {'name': 'snapshot||author', 'value': 'truocphan'}
|
117
120
|
```
|
118
121
|
---
|
119
122
|
|
@@ -182,6 +185,35 @@ print(JDKSObject.getObject())
|
|
182
185
|
```
|
183
186
|
---
|
184
187
|
|
188
|
+
### JSON_DUPLICATE_KEYS.insert(`name`, `value`, `position`=None, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
189
|
+
_Insert `value` at `position` in value list of `name`_
|
190
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
191
|
+
- `value`: new value for key `name`
|
192
|
+
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
193
|
+
- `case_insensitive`: the key name case (in)sensitive
|
194
|
+
- `separator`:
|
195
|
+
- `parse_index`:
|
196
|
+
- `dupSign_start`:
|
197
|
+
- `dupSign_end`:
|
198
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
199
|
+
```python
|
200
|
+
import json_duplicate_keys as jdks
|
201
|
+
|
202
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
203
|
+
|
204
|
+
JDKSObject = jdks.loads(Jstr)
|
205
|
+
|
206
|
+
print(JDKSObject.getObject())
|
207
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
208
|
+
|
209
|
+
JDKSObject.insert("release", {'version': '2025.1.1'})
|
210
|
+
JDKSObject.insert("snapshot||release", {'version': '2025.1.1'}, 0)
|
211
|
+
|
212
|
+
print(JDKSObject.getObject())
|
213
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}, {'version': '2025.1.1'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': '2025.1.1'}, {'version': 'latest'}]}}
|
214
|
+
```
|
215
|
+
---
|
216
|
+
|
185
217
|
### 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)
|
186
218
|
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
187
219
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
@@ -382,6 +414,9 @@ print(JDKSObject.getObject())
|
|
382
414
|
---
|
383
415
|
|
384
416
|
## CHANGELOG
|
417
|
+
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
418
|
+
- **New**: _insert_ function
|
419
|
+
|
385
420
|
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
386
421
|
- **Fixed**: Add subkey name to empty dict of existing key name
|
387
422
|
|
{json_duplicate_keys-2024.11.28 → json_duplicate_keys-2024.12.12}/json_duplicate_keys/__init__.py
RENAMED
@@ -4,12 +4,13 @@ try:
|
|
4
4
|
except NameError:
|
5
5
|
unicode = str # Python 3
|
6
6
|
|
7
|
+
from collections import OrderedDict
|
8
|
+
import json, re, copy
|
9
|
+
|
7
10
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
8
11
|
# # # # # # # # # # # Normalize Key name # # # # # # # # # # #
|
9
12
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
10
13
|
def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False):
|
11
|
-
import re
|
12
|
-
|
13
14
|
# User input data type validation
|
14
15
|
if type(_isDebug_) != bool: _isDebug_ = False
|
15
16
|
|
@@ -31,9 +32,6 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
|
|
31
32
|
# # # # # # # # # # # # # # # loads # # # # # # # # # # # # # #
|
32
33
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
33
34
|
def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
34
|
-
import json, re
|
35
|
-
from collections import OrderedDict
|
36
|
-
|
37
35
|
# User input data type validation
|
38
36
|
if type(_isDebug_) != bool: _isDebug_ = False
|
39
37
|
|
@@ -169,7 +167,6 @@ def load(Jfilepath, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False,
|
|
169
167
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
170
168
|
class JSON_DUPLICATE_KEYS:
|
171
169
|
def __init__(self, Jobj):
|
172
|
-
from collections import OrderedDict
|
173
170
|
self.__Jobj = dict()
|
174
171
|
if type(Jobj) in [dict, OrderedDict, list]:
|
175
172
|
self.__Jobj = Jobj
|
@@ -188,9 +185,6 @@ class JSON_DUPLICATE_KEYS:
|
|
188
185
|
# # # # # # # # # # # # # # # get # # # # # # # # # # # # # # #
|
189
186
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
190
187
|
def get(self, name, case_insensitive=False, separator="||", parse_index="$", _isDebug_=False):
|
191
|
-
import re
|
192
|
-
from collections import OrderedDict
|
193
|
-
|
194
188
|
# User input data type validation
|
195
189
|
if type(_isDebug_) != bool: _isDebug_ = False
|
196
190
|
|
@@ -247,9 +241,6 @@ class JSON_DUPLICATE_KEYS:
|
|
247
241
|
# # # # # # # # # # # # # # # set # # # # # # # # # # # # # # #
|
248
242
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
249
243
|
def set(self, name, value, case_insensitive=False, separator="||", parse_index="$", dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
250
|
-
import re
|
251
|
-
from collections import OrderedDict
|
252
|
-
|
253
244
|
# User input data type validation
|
254
245
|
if type(_isDebug_) != bool: _isDebug_ = False
|
255
246
|
|
@@ -329,12 +320,55 @@ class JSON_DUPLICATE_KEYS:
|
|
329
320
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
330
321
|
|
331
322
|
|
323
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
324
|
+
# # # # # # # # # # # # # # insert # # # # # # # # # # # # # #
|
325
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
326
|
+
def insert(self, name, value, position=None, case_insensitive=False, separator="||", parse_index="$", dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False):
|
327
|
+
# User input data type validation
|
328
|
+
if type(_isDebug_) != bool: _isDebug_ = False
|
329
|
+
|
330
|
+
if type(name) not in [str, unicode]:
|
331
|
+
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
332
|
+
return False
|
333
|
+
|
334
|
+
if type(position) != int: position = None
|
335
|
+
|
336
|
+
if type(case_insensitive) != bool: case_insensitive = False
|
337
|
+
|
338
|
+
if type(separator) not in [str, unicode]: separator = "||"
|
339
|
+
|
340
|
+
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
341
|
+
|
342
|
+
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
|
343
|
+
|
344
|
+
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
|
345
|
+
|
346
|
+
if type(self.getObject()) not in [list, dict, OrderedDict]:
|
347
|
+
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be list, dict or OrderedDict, not {}\x1b[0m".format(type(self.getObject())))
|
348
|
+
return False
|
349
|
+
|
350
|
+
if re.search(re.escape(separator)+"$", name):
|
351
|
+
if _isDebug_: print("\x1b[31m[-] KeyNameInvalidError: \x1b[0m"+name)
|
352
|
+
return False
|
353
|
+
|
354
|
+
Jget = self.get(name, case_insensitive=case_insensitive, separator=separator, parse_index=parse_index, _isDebug_=_isDebug_)
|
355
|
+
|
356
|
+
if Jget["value"] != "JSON_DUPLICATE_KEYS_ERROR":
|
357
|
+
if type(Jget["value"]) == list:
|
358
|
+
if position == None: position = len(Jget["value"])
|
359
|
+
|
360
|
+
Jget["value"].insert(position, value)
|
361
|
+
|
362
|
+
return self.update(Jget["name"], Jget["value"], separator=separator, parse_index=parse_index, dupSign_start=dupSign_start, dupSign_end=dupSign_end, _isDebug_=_isDebug_)
|
363
|
+
else:
|
364
|
+
if _isDebug_: print("\x1b[31m[-] DataTypeError: The data type of {} must be list, not {}\x1b[0m".format(Jget["name"], type(Jget["value"])))
|
365
|
+
return False
|
366
|
+
|
367
|
+
|
332
368
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
333
369
|
# # # # # # # # # # # # # # update # # # # # # # # # # # # # #
|
334
370
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
335
371
|
def update(self, name, value, case_insensitive=False, allow_new_key=False, separator="||", parse_index="$", dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
336
|
-
import re
|
337
|
-
|
338
372
|
# User input data type validation
|
339
373
|
if type(_isDebug_) != bool: _isDebug_ = False
|
340
374
|
|
@@ -379,8 +413,6 @@ class JSON_DUPLICATE_KEYS:
|
|
379
413
|
# # # # # # # # # # # # # # delete # # # # # # # # # # # # #
|
380
414
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
381
415
|
def delete(self, name, case_insensitive=False, separator="||", parse_index="$", _isDebug_=False):
|
382
|
-
import re
|
383
|
-
|
384
416
|
# User input data type validation
|
385
417
|
if type(_isDebug_) != bool: _isDebug_ = False
|
386
418
|
|
@@ -420,8 +452,6 @@ class JSON_DUPLICATE_KEYS:
|
|
420
452
|
# # # # # # # # # # # # filter_keys # # # # # # # # # # # # #
|
421
453
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
422
454
|
def filter_keys(self, name, separator="||", parse_index="$", ordered_dict=False):
|
423
|
-
import re, copy
|
424
|
-
|
425
455
|
JDKSObject = copy.deepcopy(self)
|
426
456
|
JDKSObject.flatten(separator=separator, parse_index=parse_index, ordered_dict=ordered_dict)
|
427
457
|
newJDKSObject = loads("{}", ordered_dict=ordered_dict)
|
@@ -444,8 +474,6 @@ class JSON_DUPLICATE_KEYS:
|
|
444
474
|
# # # # # # # # # # # # filter_values # # # # # # # # # # # # #
|
445
475
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
446
476
|
def filter_values(self, value, separator="||", parse_index="$", ordered_dict=False):
|
447
|
-
import re, copy
|
448
|
-
|
449
477
|
JDKSObject = copy.deepcopy(self)
|
450
478
|
JDKSObject.flatten(separator=separator, parse_index=parse_index, ordered_dict=ordered_dict)
|
451
479
|
newJDKSObject = loads("{}", ordered_dict=ordered_dict)
|
@@ -468,9 +496,6 @@ class JSON_DUPLICATE_KEYS:
|
|
468
496
|
# # # # # # # # # # # # # # dumps # # # # # # # # # # # # # #
|
469
497
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
470
498
|
def dumps(self, 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):
|
471
|
-
import json, re
|
472
|
-
from collections import OrderedDict
|
473
|
-
|
474
499
|
# User input data type validation
|
475
500
|
if type(_isDebug_) != bool: _isDebug_ = False
|
476
501
|
|
@@ -514,8 +539,6 @@ class JSON_DUPLICATE_KEYS:
|
|
514
539
|
# # # # # # # # # # # # # flatten # # # # # # # # # # # # # #
|
515
540
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
516
541
|
def flatten(self, separator="||", parse_index="$", ordered_dict=False, _isDebug_=False):
|
517
|
-
from collections import OrderedDict
|
518
|
-
|
519
542
|
# User input data type validation
|
520
543
|
if type(_isDebug_) != bool: _isDebug_ = False
|
521
544
|
|
@@ -575,9 +598,6 @@ class JSON_DUPLICATE_KEYS:
|
|
575
598
|
# # # # # # # # # # # # # unflatten # # # # # # # # # # # # #
|
576
599
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
577
600
|
def unflatten(self, separator="||", parse_index="$", ordered_dict=False, _isDebug_=False):
|
578
|
-
import re
|
579
|
-
from collections import OrderedDict
|
580
|
-
|
581
601
|
# User input data type validation
|
582
602
|
if type(_isDebug_) != bool: _isDebug_ = False
|
583
603
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version: 2024.
|
3
|
+
Version: 2024.12.12
|
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
|
@@ -17,12 +17,15 @@ License-File: LICENSE
|
|
17
17
|
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
18
18
|
|
19
19
|
<p align="center">
|
20
|
-
|
20
|
+
<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>
|
21
21
|
<a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
|
22
22
|
<a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
|
23
23
|
<a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
|
24
24
|
<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>
|
25
25
|
<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>
|
26
|
+
<br>
|
27
|
+
<a href="#"><img src="https://img.shields.io/pypi/v/json-duplicate-keys" height=30></a>
|
28
|
+
<a href="#"><img src="https://img.shields.io/pypi/dm/json-duplicate-keys" height=30></a>
|
26
29
|
</p>
|
27
30
|
|
28
31
|
## Installation
|
@@ -122,13 +125,13 @@ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "relea
|
|
122
125
|
JDKSObject = jdks.loads(Jstr)
|
123
126
|
|
124
127
|
print(JDKSObject.get("version{{{_2_}}}"))
|
125
|
-
# OUTPUT: latest
|
128
|
+
# OUTPUT: {'name': 'version{{{_2_}}}', 'value': 'latest'}
|
126
129
|
|
127
130
|
print(JDKSObject.get("release||$0$"))
|
128
|
-
# OUTPUT: {'version': 'latest'}
|
131
|
+
# OUTPUT: {'name': 'release||$0$', 'value': {'version': 'latest'}}
|
129
132
|
|
130
133
|
print(JDKSObject.get("snapshot||author"))
|
131
|
-
# OUTPUT: truocphan
|
134
|
+
# OUTPUT: {'name': 'snapshot||author', 'value': 'truocphan'}
|
132
135
|
```
|
133
136
|
---
|
134
137
|
|
@@ -197,6 +200,35 @@ print(JDKSObject.getObject())
|
|
197
200
|
```
|
198
201
|
---
|
199
202
|
|
203
|
+
### JSON_DUPLICATE_KEYS.insert(`name`, `value`, `position`=None, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
204
|
+
_Insert `value` at `position` in value list of `name`_
|
205
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
206
|
+
- `value`: new value for key `name`
|
207
|
+
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
208
|
+
- `case_insensitive`: the key name case (in)sensitive
|
209
|
+
- `separator`:
|
210
|
+
- `parse_index`:
|
211
|
+
- `dupSign_start`:
|
212
|
+
- `dupSign_end`:
|
213
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
214
|
+
```python
|
215
|
+
import json_duplicate_keys as jdks
|
216
|
+
|
217
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
218
|
+
|
219
|
+
JDKSObject = jdks.loads(Jstr)
|
220
|
+
|
221
|
+
print(JDKSObject.getObject())
|
222
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
223
|
+
|
224
|
+
JDKSObject.insert("release", {'version': '2025.1.1'})
|
225
|
+
JDKSObject.insert("snapshot||release", {'version': '2025.1.1'}, 0)
|
226
|
+
|
227
|
+
print(JDKSObject.getObject())
|
228
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}, {'version': '2025.1.1'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': '2025.1.1'}, {'version': 'latest'}]}}
|
229
|
+
```
|
230
|
+
---
|
231
|
+
|
200
232
|
### 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)
|
201
233
|
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
202
234
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
@@ -397,6 +429,9 @@ print(JDKSObject.getObject())
|
|
397
429
|
---
|
398
430
|
|
399
431
|
## CHANGELOG
|
432
|
+
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
433
|
+
- **New**: _insert_ function
|
434
|
+
|
400
435
|
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
401
436
|
- **Fixed**: Add subkey name to empty dict of existing key name
|
402
437
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|