json-duplicate-keys 2024.11.19__py2-none-any.whl → 2024.11.28__py2-none-any.whl
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/__init__.py +26 -17
- {json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/METADATA +12 -5
- json_duplicate_keys-2024.11.28.dist-info/RECORD +6 -0
- json_duplicate_keys-2024.11.19.dist-info/RECORD +0 -6
- {json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/LICENSE +0 -0
- {json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/WHEEL +0 -0
- {json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/top_level.txt +0 -0
json_duplicate_keys/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
try:
|
2
3
|
unicode # Python 2
|
3
4
|
except NameError:
|
@@ -150,9 +151,8 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
|
|
150
151
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
151
152
|
def load(Jfilepath, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
152
153
|
try:
|
153
|
-
|
154
|
-
|
155
|
-
Jfile.close()
|
154
|
+
with open(Jfilepath) as Jfile:
|
155
|
+
Jstr = Jfile.read()
|
156
156
|
|
157
157
|
return loads(Jstr, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, _isDebug_=_isDebug_)
|
158
158
|
except Exception as e:
|
@@ -307,16 +307,20 @@ class JSON_DUPLICATE_KEYS:
|
|
307
307
|
else:
|
308
308
|
if self.get(separator.join(name.split(separator)[:-1]), case_insensitive=case_insensitive, separator=separator, parse_index=parse_index)["value"] != "JSON_DUPLICATE_KEYS_ERROR":
|
309
309
|
Jget = self.get(separator.join(name.split(separator)[:-1]), case_insensitive=case_insensitive, separator=separator, parse_index=parse_index)
|
310
|
-
|
310
|
+
if type(Jget["value"]) in [dict, OrderedDict]:
|
311
|
+
exec_expression = "self.getObject()"
|
311
312
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
313
|
+
for k in Jget["name"].split(separator)+[name.split(separator)[-1]]:
|
314
|
+
if re.search("^"+re.escape(parse_index)+"\\d+"+re.escape(parse_index)+"$", k):
|
315
|
+
exec_expression += "["+k.split(parse_index)[1]+"]"
|
316
|
+
else:
|
317
|
+
exec_expression += "["+repr(k)+"]"
|
317
318
|
|
318
|
-
|
319
|
-
|
319
|
+
exec(exec_expression+"="+repr(value))
|
320
|
+
return True
|
321
|
+
else:
|
322
|
+
if _isDebug_: print("\x1b[31m[-] KeyNameInvalidError: \x1b[0m"+name)
|
323
|
+
return False
|
320
324
|
else:
|
321
325
|
if _isDebug_: print("\x1b[31m[-] KeyNameNotExistError: {}\x1b[0m".format(separator.join(Jget["name"].split(separator)[:-1])))
|
322
326
|
return False
|
@@ -328,7 +332,7 @@ class JSON_DUPLICATE_KEYS:
|
|
328
332
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
329
333
|
# # # # # # # # # # # # # # update # # # # # # # # # # # # # #
|
330
334
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
331
|
-
def update(self, name, value, case_insensitive=False, separator="||", parse_index="$", _isDebug_=False):
|
335
|
+
def update(self, name, value, case_insensitive=False, allow_new_key=False, separator="||", parse_index="$", dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
332
336
|
import re
|
333
337
|
|
334
338
|
# User input data type validation
|
@@ -344,7 +348,10 @@ class JSON_DUPLICATE_KEYS:
|
|
344
348
|
|
345
349
|
if type(parse_index) not in [str, unicode]: parse_index = "$"
|
346
350
|
|
347
|
-
|
351
|
+
_debug_ = _isDebug_
|
352
|
+
if allow_new_key: _debug_ = False
|
353
|
+
|
354
|
+
if self.get(name, case_insensitive=case_insensitive, separator=separator, parse_index=parse_index, _isDebug_=_debug_)["value"] != "JSON_DUPLICATE_KEYS_ERROR":
|
348
355
|
Jname = self.get(name, case_insensitive=case_insensitive, separator=separator, parse_index=parse_index)["name"]
|
349
356
|
try:
|
350
357
|
exec_expression = "self.getObject()"
|
@@ -359,6 +366,8 @@ class JSON_DUPLICATE_KEYS:
|
|
359
366
|
return True
|
360
367
|
except Exception as e:
|
361
368
|
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
|
369
|
+
elif allow_new_key:
|
370
|
+
return self.set(name, value, case_insensitive=case_insensitive, separator=separator, parse_index=parse_index, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, _isDebug_=_isDebug_)
|
362
371
|
|
363
372
|
return False
|
364
373
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -420,10 +429,10 @@ class JSON_DUPLICATE_KEYS:
|
|
420
429
|
for k, v in JDKSObject.getObject().items():
|
421
430
|
if type(k) == str and type(name) == str:
|
422
431
|
if re.search(name, k):
|
423
|
-
newJDKSObject.set(k, v, separator="
|
432
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
424
433
|
else:
|
425
434
|
if name == k:
|
426
|
-
newJDKSObject.set(k, v, separator="
|
435
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
427
436
|
|
428
437
|
return newJDKSObject
|
429
438
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -444,10 +453,10 @@ class JSON_DUPLICATE_KEYS:
|
|
444
453
|
for k, v in JDKSObject.getObject().items():
|
445
454
|
if type(v) == str and type(value) == str:
|
446
455
|
if re.search(value, v):
|
447
|
-
newJDKSObject.set(k, v, separator="
|
456
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
448
457
|
else:
|
449
458
|
if value == v:
|
450
|
-
newJDKSObject.set(k, v, separator="
|
459
|
+
newJDKSObject.set(k, v, separator="§§"+separator+"§§", parse_index="§§"+parse_index+"§§", ordered_dict=ordered_dict)
|
451
460
|
|
452
461
|
return newJDKSObject
|
453
462
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
{json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version: 2024.11.
|
3
|
+
Version: 2024.11.28
|
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
|
@@ -197,13 +197,17 @@ print(JDKSObject.getObject())
|
|
197
197
|
```
|
198
198
|
---
|
199
199
|
|
200
|
-
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
201
|
-
_Update new `value` for existing `name` in the JSON object_
|
200
|
+
### 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
|
+
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
202
202
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
203
203
|
- `value`: new value for key `name`
|
204
204
|
- `case_insensitive`: the key name case (in)sensitive
|
205
|
+
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
205
206
|
- `separator`:
|
206
207
|
- `parse_index`:
|
208
|
+
- `dupSign_start`:
|
209
|
+
- `dupSign_end`:
|
210
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
207
211
|
- `_isDebug_`: Show/ Hide debug error messages
|
208
212
|
```python
|
209
213
|
import json_duplicate_keys as jdks
|
@@ -254,7 +258,7 @@ print(JDKSObject.getObject())
|
|
254
258
|
- `name`:
|
255
259
|
- `separator`:
|
256
260
|
- `parse_index`:
|
257
|
-
- `ordered_dict`:
|
261
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
258
262
|
```python
|
259
263
|
import json_duplicate_keys as jdks
|
260
264
|
|
@@ -275,7 +279,7 @@ print(JDKSObject.dumps())
|
|
275
279
|
- `value`:
|
276
280
|
- `separator`:
|
277
281
|
- `parse_index`:
|
278
|
-
- `ordered_dict`:
|
282
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
279
283
|
```python
|
280
284
|
import json_duplicate_keys as jdks
|
281
285
|
|
@@ -393,6 +397,9 @@ print(JDKSObject.getObject())
|
|
393
397
|
---
|
394
398
|
|
395
399
|
## CHANGELOG
|
400
|
+
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
401
|
+
- **Fixed**: Add subkey name to empty dict of existing key name
|
402
|
+
|
396
403
|
#### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
|
397
404
|
- **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
|
398
405
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
json_duplicate_keys/__init__.py,SHA256=YV3PpNeXAynBoY46yTs_M3t3KivpXvOLdeMD__IyviM,27170
|
2
|
+
json_duplicate_keys-2024.11.28.dist-info/LICENSE,SHA256=_hudSGMciUc27wGR8EMKfeb3atJRlf6rbhJtLnel-nc,1093
|
3
|
+
json_duplicate_keys-2024.11.28.dist-info/METADATA,SHA256=YsVbH-oTT_YslwHqdluw1470mrSvgg4iO50cNcKHPdk,18243
|
4
|
+
json_duplicate_keys-2024.11.28.dist-info/WHEEL,SHA256=1VPi6hfNQaRRNuEdK_3dv9o8COtLGnHWJghhj4CQ28k,92
|
5
|
+
json_duplicate_keys-2024.11.28.dist-info/top_level.txt,SHA256=vdsGrPLVS_l-BFL1i4hCJBY5_-gq4Cwp-11yegA750Y,20
|
6
|
+
json_duplicate_keys-2024.11.28.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
json_duplicate_keys/__init__.py,SHA256=K9bg6uSaRnP4JNorn0Y_Chw_ZnRIZoIU0RGxqHFk8-s,26545
|
2
|
-
json_duplicate_keys-2024.11.19.dist-info/LICENSE,SHA256=_hudSGMciUc27wGR8EMKfeb3atJRlf6rbhJtLnel-nc,1093
|
3
|
-
json_duplicate_keys-2024.11.19.dist-info/METADATA,SHA256=ytf0YHsh6CsnhIZdaihik1ibZkabt6J1QsHkhbpAlno,17673
|
4
|
-
json_duplicate_keys-2024.11.19.dist-info/WHEEL,SHA256=1VPi6hfNQaRRNuEdK_3dv9o8COtLGnHWJghhj4CQ28k,92
|
5
|
-
json_duplicate_keys-2024.11.19.dist-info/top_level.txt,SHA256=vdsGrPLVS_l-BFL1i4hCJBY5_-gq4Cwp-11yegA750Y,20
|
6
|
-
json_duplicate_keys-2024.11.19.dist-info/RECORD,,
|
{json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/LICENSE
RENAMED
File without changes
|
File without changes
|
{json_duplicate_keys-2024.11.19.dist-info → json_duplicate_keys-2024.11.28.dist-info}/top_level.txt
RENAMED
File without changes
|