Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 994e19f

Browse files
committed
Released json-duplicate-keys v2024.3.24
1 parent 25dd862 commit 994e19f

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# JSON Duplicate Keys
1+
# JSON Duplicate Keys - PyPI
22
Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
33

44
<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>
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>
1111
<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>
1212
<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>
1313
<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>
@@ -356,4 +356,9 @@ JDKSObject.unflatten()
356356
print(JDKSObject.getObject())
357357
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
358358
```
359+
---
360+
361+
## CHANGELOG
362+
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
363+
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
359364
---

json_duplicate_keys/__init__.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
88
if type(_isDebug_) != bool: _isDebug_ = False
99
try:
1010
if type(name) not in [str, unicode]:
11-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
12-
exit()
11+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
1312
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
1413
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
1514
except Exception as e:
1615
if type(name) not in [str]:
17-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
18-
exit()
16+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
1917
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
2018
if type(dupSign_end) not in [str]: dupSign_end = "}}}"
2119

@@ -37,14 +35,12 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
3735
if type(ordered_dict) != bool: ordered_dict = False
3836
try:
3937
if type(Jstr) not in [str, unicode]:
40-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
41-
exit()
38+
exit("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
4239
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
4340
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
4441
except Exception as e:
4542
if type(Jstr) not in [str]:
46-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
47-
exit()
43+
exit("\x1b[31m[-] DataTypeError: the JSON object must be str or unicode, not {}\x1b[0m".format(type(Jstr)))
4844
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
4945
if type(dupSign_end) not in [str]: dupSign_end = "}}}"
5046

@@ -195,14 +191,12 @@ def get(self, name, separator="||", parse_index="$", _isDebug_=False):
195191
if type(_isDebug_) != bool: _isDebug_ = False
196192
try:
197193
if type(name) not in [str, unicode]:
198-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
199-
exit()
194+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
200195
if type(separator) not in [str, unicode]: separator = "||"
201196
if type(parse_index) not in [str, unicode]: parse_index = "$"
202197
except Exception as e:
203198
if type(name) not in [str]:
204-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
205-
exit()
199+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
206200
if type(separator) not in [str]: separator = "||"
207201
if type(parse_index) not in [str]: parse_index = "$"
208202

@@ -246,16 +240,14 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
246240
if type(ordered_dict) != bool: ordered_dict = False
247241
try:
248242
if type(name) not in [str, unicode]:
249-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
250-
exit()
243+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
251244
if type(separator) not in [str, unicode]: separator = "||"
252245
if type(parse_index) not in [str, unicode]: parse_index = "$"
253246
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
254247
if type(dupSign_end) not in [str, unicode]: dupSign_end = "}}}"
255248
except Exception as e:
256249
if type(name) not in [str]:
257-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
258-
exit()
250+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
259251
if type(separator) not in [str]: separator = "||"
260252
if type(parse_index) not in [str]: parse_index = "$"
261253
if type(dupSign_start) not in [str]: dupSign_start = "{{{"
@@ -308,6 +300,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
308300
exec_expression += "["+repr(k)+"]"
309301

310302
exec(exec_expression+"="+repr(value))
303+
return True
311304
# Add new key
312305
elif self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index) != "JSON_DUPLICATE_KEYS_ERROR":
313306
if type(self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index)) == list:
@@ -331,6 +324,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
331324
exec_expression += "["+repr(k)+"]"
332325

333326
exec(exec_expression+".append({"+repr(name_split_lastKey)+":"+repr(value)+"})")
327+
return True
334328
elif type(self.get(separator.join(name_split_first), separator=separator, parse_index=parse_index)) == dict:
335329
exec_expression = "self.getObject()"
336330

@@ -341,6 +335,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
341335
exec_expression += "["+repr(k)+"]"
342336

343337
exec(exec_expression+"["+repr(name_split_lastKey)+"]="+repr(value))
338+
return True
344339
else:
345340
if _isDebug_: print("\x1b[31m[-] KeyNameNotExistError: {}\x1b[0m".format(separator.join(name_split_first)))
346341
# Add new key
@@ -352,6 +347,7 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
352347
self.__Jobj.append({name_split_lastKey: value})
353348
else:
354349
self.__Jobj[name_split_lastKey] = value
350+
return True
355351
else:
356352
if _isDebug_: print("\x1b[31m[-] KeyNameInvalidError: {}\x1b[0m".format(separator.join(name_split_first)))
357353
else:
@@ -360,6 +356,8 @@ def set(self, name, value, separator="||", parse_index="$", dupSign_start="{{{",
360356
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
361357
else:
362358
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
363361
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
364362
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
365363
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -375,14 +373,12 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
375373
if type(_isDebug_) != bool: _isDebug_ = False
376374
try:
377375
if type(name) not in [str, unicode]:
378-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
379-
exit()
376+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
380377
if type(separator) not in [str, unicode]: separator = "||"
381378
if type(parse_index) not in [str, unicode]: parse_index = "$"
382379
except Exception as e:
383380
if type(name) not in [str]:
384-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
385-
exit()
381+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
386382
if type(separator) not in [str]: separator = "||"
387383
if type(parse_index) not in [str]: parse_index = "$"
388384

@@ -397,8 +393,11 @@ def update(self, name, value, separator="||", parse_index="$", _isDebug_=False):
397393
exec_expression += "["+repr(k)+"]"
398394

399395
exec(exec_expression+"="+repr(value))
396+
return True
400397
except Exception as e:
401398
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
399+
400+
return False
402401
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
403402
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
404403
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -415,14 +414,12 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
415414

416415
try:
417416
if type(name) not in [str, unicode]:
418-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
419-
exit()
417+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
420418
if type(separator) not in [str, unicode]: separator = "||"
421419
if type(parse_index) not in [str, unicode]: parse_index = "$"
422420
except Exception as e:
423421
if type(name) not in [str]:
424-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
425-
exit()
422+
exit("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
426423
if type(separator) not in [str]: separator = "||"
427424
if type(parse_index) not in [str]: parse_index = "$"
428425

@@ -437,8 +434,11 @@ def delete(self, name, separator="||", parse_index="$", _isDebug_=False):
437434
exec_expression += "["+repr(k)+"]"
438435

439436
exec(exec_expression)
437+
return True
440438
except Exception as e:
441439
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
440+
441+
return False
442442
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
443443
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
444444
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setuptools.setup(
44
name="json-duplicate-keys",
5-
version="2024.2.21",
5+
version="2024.3.24",
66
author="TP Cyber Security",
77
license="MIT",
88
author_email="[email protected]",

0 commit comments

Comments
 (0)