json-duplicate-keys 2024.12.12__tar.gz → 2025.7.1__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.12.12/json_duplicate_keys.egg-info → json_duplicate_keys-2025.7.1}/PKG-INFO +49 -58
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/README.md +48 -57
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/json_duplicate_keys/__init__.py +72 -39
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1/json_duplicate_keys.egg-info}/PKG-INFO +49 -58
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/setup.py +3 -2
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/LICENSE +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/MANIFEST.in +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/json_duplicate_keys.egg-info/SOURCES.txt +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/json_duplicate_keys.egg-info/dependency_links.txt +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/json_duplicate_keys.egg-info/top_level.txt +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/requirements.txt +0 -0
- {json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version:
|
3
|
+
Version: 2025.7.1
|
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
|
@@ -45,8 +45,8 @@ python setup.py install
|
|
45
45
|
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
46
46
|
_Normalize Key name_
|
47
47
|
- `name`: key name
|
48
|
-
- `dupSign_start`:
|
49
|
-
- `dupSign_end`:
|
48
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
49
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
50
50
|
- `_isDebug_`: Show/ Hide debug error messages
|
51
51
|
```python
|
52
52
|
import json_duplicate_keys as jdks
|
@@ -56,12 +56,13 @@ print(jdks.normalize_key("version{{{_2_}}}"))
|
|
56
56
|
```
|
57
57
|
---
|
58
58
|
|
59
|
-
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
59
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
60
60
|
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
61
61
|
- `Jstr`: a JSON format string
|
62
|
-
- `dupSign_start`:
|
63
|
-
- `dupSign_end`:
|
62
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
63
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
64
64
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
65
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
65
66
|
- `_isDebug_`: Show/ Hide debug error messages
|
66
67
|
```python
|
67
68
|
import json_duplicate_keys as jdks
|
@@ -75,12 +76,13 @@ print(JDKSObject)
|
|
75
76
|
```
|
76
77
|
---
|
77
78
|
|
78
|
-
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
79
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
79
80
|
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
80
81
|
- `Jfilepath`: The path to the file containing the JSON format string
|
81
|
-
- `dupSign_start`:
|
82
|
-
- `dupSign_end`:
|
82
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
83
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
83
84
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
85
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
84
86
|
- `_isDebug_`: Show/ Hide debug error messages
|
85
87
|
```python
|
86
88
|
# /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"}]}}
|
@@ -114,8 +116,8 @@ print(JDKSObject.getObject())
|
|
114
116
|
_Get value in the JSON object by `name`_
|
115
117
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
116
118
|
- `case_insensitive`: the key name case (in)sensitive
|
117
|
-
- `separator`:
|
118
|
-
- `parse_index`:
|
119
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
120
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
119
121
|
- `_isDebug_`: Show/ Hide debug error messages
|
120
122
|
```python
|
121
123
|
import json_duplicate_keys as jdks
|
@@ -140,10 +142,10 @@ _Set a new `name` and `value` for the JSON object_
|
|
140
142
|
- `name`: new key name for the JSON object. Supported flat key name format
|
141
143
|
- `value`: value for key `name`
|
142
144
|
- `case_insensitive`: the key name case (in)sensitive
|
143
|
-
- `separator`:
|
144
|
-
- `parse_index`:
|
145
|
-
- `dupSign_start`:
|
146
|
-
- `dupSign_end`:
|
145
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
146
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
147
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
148
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
147
149
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
148
150
|
- `_isDebug_`: Show/Hide debug error messages
|
149
151
|
```python
|
@@ -178,25 +180,6 @@ print(JDKSObject.getObject())
|
|
178
180
|
JDKSObject.set("snapshot||author", "truocphan")
|
179
181
|
print(JDKSObject.getObject())
|
180
182
|
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
181
|
-
|
182
|
-
|
183
|
-
Jstr = '[]'
|
184
|
-
JDKSObject = jdks.loads(Jstr)
|
185
|
-
|
186
|
-
print(JDKSObject.getObject())
|
187
|
-
# OUTPUT: []
|
188
|
-
|
189
|
-
JDKSObject.set("author", "truocphan")
|
190
|
-
print(JDKSObject.getObject())
|
191
|
-
# OUTPUT: [{'author': 'truocphan'}]
|
192
|
-
|
193
|
-
JDKSObject.set("release", [])
|
194
|
-
print(JDKSObject.getObject())
|
195
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
196
|
-
|
197
|
-
JDKSObject.set("$1$||release||", {"version": "latest"})
|
198
|
-
print(JDKSObject.getObject())
|
199
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
200
183
|
```
|
201
184
|
---
|
202
185
|
|
@@ -206,10 +189,10 @@ _Insert `value` at `position` in value list of `name`_
|
|
206
189
|
- `value`: new value for key `name`
|
207
190
|
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
208
191
|
- `case_insensitive`: the key name case (in)sensitive
|
209
|
-
- `separator`:
|
210
|
-
- `parse_index`:
|
211
|
-
- `dupSign_start`:
|
212
|
-
- `dupSign_end`:
|
192
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
193
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
194
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
195
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
213
196
|
- `_isDebug_`: Show/ Hide debug error messages
|
214
197
|
```python
|
215
198
|
import json_duplicate_keys as jdks
|
@@ -235,10 +218,10 @@ _Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
|
235
218
|
- `value`: new value for key `name`
|
236
219
|
- `case_insensitive`: the key name case (in)sensitive
|
237
220
|
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
238
|
-
- `separator`:
|
239
|
-
- `parse_index`:
|
240
|
-
- `dupSign_start`:
|
241
|
-
- `dupSign_end`:
|
221
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
222
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
223
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
224
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
242
225
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
243
226
|
- `_isDebug_`: Show/ Hide debug error messages
|
244
227
|
```python
|
@@ -263,8 +246,8 @@ print(JDKSObject.getObject())
|
|
263
246
|
_Delete a key-value pair in a JSON object by key `name`_
|
264
247
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
265
248
|
- `case_insensitive`: the key name case (in)sensitive
|
266
|
-
- `separator`:
|
267
|
-
- `parse_index`:
|
249
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
250
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
268
251
|
- `_isDebug_`: Show/ Hide debug error messages
|
269
252
|
```python
|
270
253
|
import json_duplicate_keys as jdks
|
@@ -286,10 +269,10 @@ print(JDKSObject.getObject())
|
|
286
269
|
---
|
287
270
|
|
288
271
|
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
289
|
-
|
272
|
+
_Return a `JSON_DUPLICATE_KEYS` object with keys matching a pattern_
|
290
273
|
- `name`:
|
291
|
-
- `separator`:
|
292
|
-
- `parse_index`:
|
274
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
275
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
293
276
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
294
277
|
```python
|
295
278
|
import json_duplicate_keys as jdks
|
@@ -307,10 +290,10 @@ print(JDKSObject.dumps())
|
|
307
290
|
---
|
308
291
|
|
309
292
|
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
310
|
-
|
293
|
+
_Return a `JSON_DUPLICATE_KEYS` object with values matching a pattern_
|
311
294
|
- `value`:
|
312
|
-
- `separator`:
|
313
|
-
- `parse_index`:
|
295
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
296
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
314
297
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
315
298
|
```python
|
316
299
|
import json_duplicate_keys as jdks
|
@@ -329,8 +312,8 @@ print(JDKSObject.dumps())
|
|
329
312
|
|
330
313
|
### 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)
|
331
314
|
_Serialize a JSON object to a JSON format string_
|
332
|
-
- `dupSign_start`:
|
333
|
-
- `dupSign_end`:
|
315
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
316
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
334
317
|
- `_isDebug_`: Show/ Hide debug error messages
|
335
318
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
336
319
|
```python
|
@@ -355,8 +338,8 @@ print(JDKSObject.dumps())
|
|
355
338
|
### 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)
|
356
339
|
_Serialize a JSON object to a JSON format string and write to a file_
|
357
340
|
- `Jfilepath`: the path to the file to save the JSON format string
|
358
|
-
- `dupSign_start`:
|
359
|
-
- `dupSign_end`:
|
341
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
342
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
360
343
|
- `_isDebug_`: Show/ Hide debug error messages
|
361
344
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
362
345
|
```python
|
@@ -384,8 +367,8 @@ print(JDKSObject_load.getObject())
|
|
384
367
|
|
385
368
|
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
386
369
|
_Flatten a JSON object to a single key-value pairs_
|
387
|
-
- `separator`:
|
388
|
-
- `parse_index`:
|
370
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
371
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
389
372
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
390
373
|
- `_isDebug_`: Show/ Hide debug error messages
|
391
374
|
```python
|
@@ -407,8 +390,8 @@ print(JDKSObject.getObject())
|
|
407
390
|
|
408
391
|
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
409
392
|
_Unflatten a flattened JSON object back to a JSON object_
|
410
|
-
- `separator`:
|
411
|
-
- `parse_index`:
|
393
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
394
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
412
395
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
413
396
|
- `_isDebug_`: Show/ Hide debug error messages
|
414
397
|
```python
|
@@ -429,6 +412,14 @@ print(JDKSObject.getObject())
|
|
429
412
|
---
|
430
413
|
|
431
414
|
## CHANGELOG
|
415
|
+
#### [json-duplicate-keys v2025.7.1](https://github.com/truocphan/json-duplicate-keys/tree/2025.7.1)
|
416
|
+
- [**Updated**] Fixed some issues when loading JSON strings with `skipDuplicated` option
|
417
|
+
- [**Updated**] Allow loading of JSON data in byte string format
|
418
|
+
- [**Updated**] Issue with getting and setting an empty list
|
419
|
+
|
420
|
+
#### [json-duplicate-keys v2025.6.6](https://github.com/truocphan/json-duplicate-keys/tree/2025.6.6)
|
421
|
+
- [**Updated**] Added `skipDuplicated` parameter to `load` and `loads` functions to improve performance when parsing large JSON strings by skipping duplicate keys.
|
422
|
+
|
432
423
|
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
433
424
|
- **New**: _insert_ function
|
434
425
|
|
@@ -30,8 +30,8 @@ python setup.py install
|
|
30
30
|
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
31
31
|
_Normalize Key name_
|
32
32
|
- `name`: key name
|
33
|
-
- `dupSign_start`:
|
34
|
-
- `dupSign_end`:
|
33
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
34
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
35
35
|
- `_isDebug_`: Show/ Hide debug error messages
|
36
36
|
```python
|
37
37
|
import json_duplicate_keys as jdks
|
@@ -41,12 +41,13 @@ print(jdks.normalize_key("version{{{_2_}}}"))
|
|
41
41
|
```
|
42
42
|
---
|
43
43
|
|
44
|
-
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
44
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
45
45
|
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
46
46
|
- `Jstr`: a JSON format string
|
47
|
-
- `dupSign_start`:
|
48
|
-
- `dupSign_end`:
|
47
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
48
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
49
49
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
50
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
50
51
|
- `_isDebug_`: Show/ Hide debug error messages
|
51
52
|
```python
|
52
53
|
import json_duplicate_keys as jdks
|
@@ -60,12 +61,13 @@ print(JDKSObject)
|
|
60
61
|
```
|
61
62
|
---
|
62
63
|
|
63
|
-
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
64
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
64
65
|
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
65
66
|
- `Jfilepath`: The path to the file containing the JSON format string
|
66
|
-
- `dupSign_start`:
|
67
|
-
- `dupSign_end`:
|
67
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
68
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
68
69
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
70
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
69
71
|
- `_isDebug_`: Show/ Hide debug error messages
|
70
72
|
```python
|
71
73
|
# /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"}]}}
|
@@ -99,8 +101,8 @@ print(JDKSObject.getObject())
|
|
99
101
|
_Get value in the JSON object by `name`_
|
100
102
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
101
103
|
- `case_insensitive`: the key name case (in)sensitive
|
102
|
-
- `separator`:
|
103
|
-
- `parse_index`:
|
104
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
105
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
104
106
|
- `_isDebug_`: Show/ Hide debug error messages
|
105
107
|
```python
|
106
108
|
import json_duplicate_keys as jdks
|
@@ -125,10 +127,10 @@ _Set a new `name` and `value` for the JSON object_
|
|
125
127
|
- `name`: new key name for the JSON object. Supported flat key name format
|
126
128
|
- `value`: value for key `name`
|
127
129
|
- `case_insensitive`: the key name case (in)sensitive
|
128
|
-
- `separator`:
|
129
|
-
- `parse_index`:
|
130
|
-
- `dupSign_start`:
|
131
|
-
- `dupSign_end`:
|
130
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
131
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
132
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
133
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
132
134
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
133
135
|
- `_isDebug_`: Show/Hide debug error messages
|
134
136
|
```python
|
@@ -163,25 +165,6 @@ print(JDKSObject.getObject())
|
|
163
165
|
JDKSObject.set("snapshot||author", "truocphan")
|
164
166
|
print(JDKSObject.getObject())
|
165
167
|
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
166
|
-
|
167
|
-
|
168
|
-
Jstr = '[]'
|
169
|
-
JDKSObject = jdks.loads(Jstr)
|
170
|
-
|
171
|
-
print(JDKSObject.getObject())
|
172
|
-
# OUTPUT: []
|
173
|
-
|
174
|
-
JDKSObject.set("author", "truocphan")
|
175
|
-
print(JDKSObject.getObject())
|
176
|
-
# OUTPUT: [{'author': 'truocphan'}]
|
177
|
-
|
178
|
-
JDKSObject.set("release", [])
|
179
|
-
print(JDKSObject.getObject())
|
180
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
181
|
-
|
182
|
-
JDKSObject.set("$1$||release||", {"version": "latest"})
|
183
|
-
print(JDKSObject.getObject())
|
184
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
185
168
|
```
|
186
169
|
---
|
187
170
|
|
@@ -191,10 +174,10 @@ _Insert `value` at `position` in value list of `name`_
|
|
191
174
|
- `value`: new value for key `name`
|
192
175
|
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
193
176
|
- `case_insensitive`: the key name case (in)sensitive
|
194
|
-
- `separator`:
|
195
|
-
- `parse_index`:
|
196
|
-
- `dupSign_start`:
|
197
|
-
- `dupSign_end`:
|
177
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
178
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
179
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
180
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
198
181
|
- `_isDebug_`: Show/ Hide debug error messages
|
199
182
|
```python
|
200
183
|
import json_duplicate_keys as jdks
|
@@ -220,10 +203,10 @@ _Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
|
220
203
|
- `value`: new value for key `name`
|
221
204
|
- `case_insensitive`: the key name case (in)sensitive
|
222
205
|
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
223
|
-
- `separator`:
|
224
|
-
- `parse_index`:
|
225
|
-
- `dupSign_start`:
|
226
|
-
- `dupSign_end`:
|
206
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
207
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
208
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
209
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
227
210
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
228
211
|
- `_isDebug_`: Show/ Hide debug error messages
|
229
212
|
```python
|
@@ -248,8 +231,8 @@ print(JDKSObject.getObject())
|
|
248
231
|
_Delete a key-value pair in a JSON object by key `name`_
|
249
232
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
250
233
|
- `case_insensitive`: the key name case (in)sensitive
|
251
|
-
- `separator`:
|
252
|
-
- `parse_index`:
|
234
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
235
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
253
236
|
- `_isDebug_`: Show/ Hide debug error messages
|
254
237
|
```python
|
255
238
|
import json_duplicate_keys as jdks
|
@@ -271,10 +254,10 @@ print(JDKSObject.getObject())
|
|
271
254
|
---
|
272
255
|
|
273
256
|
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
274
|
-
|
257
|
+
_Return a `JSON_DUPLICATE_KEYS` object with keys matching a pattern_
|
275
258
|
- `name`:
|
276
|
-
- `separator`:
|
277
|
-
- `parse_index`:
|
259
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
260
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
278
261
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
279
262
|
```python
|
280
263
|
import json_duplicate_keys as jdks
|
@@ -292,10 +275,10 @@ print(JDKSObject.dumps())
|
|
292
275
|
---
|
293
276
|
|
294
277
|
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
295
|
-
|
278
|
+
_Return a `JSON_DUPLICATE_KEYS` object with values matching a pattern_
|
296
279
|
- `value`:
|
297
|
-
- `separator`:
|
298
|
-
- `parse_index`:
|
280
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
281
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
299
282
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
300
283
|
```python
|
301
284
|
import json_duplicate_keys as jdks
|
@@ -314,8 +297,8 @@ print(JDKSObject.dumps())
|
|
314
297
|
|
315
298
|
### 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)
|
316
299
|
_Serialize a JSON object to a JSON format string_
|
317
|
-
- `dupSign_start`:
|
318
|
-
- `dupSign_end`:
|
300
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
301
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
319
302
|
- `_isDebug_`: Show/ Hide debug error messages
|
320
303
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
321
304
|
```python
|
@@ -340,8 +323,8 @@ print(JDKSObject.dumps())
|
|
340
323
|
### 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)
|
341
324
|
_Serialize a JSON object to a JSON format string and write to a file_
|
342
325
|
- `Jfilepath`: the path to the file to save the JSON format string
|
343
|
-
- `dupSign_start`:
|
344
|
-
- `dupSign_end`:
|
326
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
327
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
345
328
|
- `_isDebug_`: Show/ Hide debug error messages
|
346
329
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
347
330
|
```python
|
@@ -369,8 +352,8 @@ print(JDKSObject_load.getObject())
|
|
369
352
|
|
370
353
|
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
371
354
|
_Flatten a JSON object to a single key-value pairs_
|
372
|
-
- `separator`:
|
373
|
-
- `parse_index`:
|
355
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
356
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
374
357
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
375
358
|
- `_isDebug_`: Show/ Hide debug error messages
|
376
359
|
```python
|
@@ -392,8 +375,8 @@ print(JDKSObject.getObject())
|
|
392
375
|
|
393
376
|
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
394
377
|
_Unflatten a flattened JSON object back to a JSON object_
|
395
|
-
- `separator`:
|
396
|
-
- `parse_index`:
|
378
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
379
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
397
380
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
398
381
|
- `_isDebug_`: Show/ Hide debug error messages
|
399
382
|
```python
|
@@ -414,6 +397,14 @@ print(JDKSObject.getObject())
|
|
414
397
|
---
|
415
398
|
|
416
399
|
## CHANGELOG
|
400
|
+
#### [json-duplicate-keys v2025.7.1](https://github.com/truocphan/json-duplicate-keys/tree/2025.7.1)
|
401
|
+
- [**Updated**] Fixed some issues when loading JSON strings with `skipDuplicated` option
|
402
|
+
- [**Updated**] Allow loading of JSON data in byte string format
|
403
|
+
- [**Updated**] Issue with getting and setting an empty list
|
404
|
+
|
405
|
+
#### [json-duplicate-keys v2025.6.6](https://github.com/truocphan/json-duplicate-keys/tree/2025.6.6)
|
406
|
+
- [**Updated**] Added `skipDuplicated` parameter to `load` and `loads` functions to improve performance when parsing large JSON strings by skipping duplicate keys.
|
407
|
+
|
417
408
|
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
418
409
|
- **New**: _insert_ function
|
419
410
|
|
{json_duplicate_keys-2024.12.12 → json_duplicate_keys-2025.7.1}/json_duplicate_keys/__init__.py
RENAMED
@@ -1,4 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
json_duplicate_keys_VERSION = "2025.7.1"
|
3
|
+
|
2
4
|
try:
|
3
5
|
unicode # Python 2
|
4
6
|
except NameError:
|
@@ -31,14 +33,16 @@ def normalize_key(name, dupSign_start="{{{", dupSign_end="}}}", _isDebug_=False)
|
|
31
33
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
32
34
|
# # # # # # # # # # # # # # # loads # # # # # # # # # # # # # #
|
33
35
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
34
|
-
def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
36
|
+
def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, skipDuplicated=False, _isDebug_=False):
|
35
37
|
# User input data type validation
|
36
38
|
if type(_isDebug_) != bool: _isDebug_ = False
|
37
39
|
|
40
|
+
if type(skipDuplicated) != bool: skipDuplicated = False
|
41
|
+
|
38
42
|
if type(ordered_dict) != bool: ordered_dict = False
|
39
43
|
|
40
|
-
if type(Jstr) not in [str, unicode]:
|
41
|
-
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be str or
|
44
|
+
if type(Jstr) not in [str, unicode, bytes]:
|
45
|
+
if _isDebug_: print("\x1b[31m[-] DataTypeError: the JSON object must be str, unicode or bytes, not {}\x1b[0m".format(type(Jstr)))
|
42
46
|
return False
|
43
47
|
|
44
48
|
if type(dupSign_start) not in [str, unicode]: dupSign_start = "{{{"
|
@@ -93,6 +97,13 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
|
|
93
97
|
Jloads = json.loads(Jstr)
|
94
98
|
if ordered_dict: Jloads = json.loads(Jstr, object_pairs_hook=OrderedDict)
|
95
99
|
|
100
|
+
if skipDuplicated:
|
101
|
+
if type(Jloads) in [list, dict, OrderedDict]:
|
102
|
+
return JSON_DUPLICATE_KEYS(Jloads)
|
103
|
+
else:
|
104
|
+
if _isDebug_: print("\x1b[31m[-] DataError: Invalid JSON format\x1b[0m")
|
105
|
+
return False
|
106
|
+
|
96
107
|
if type(Jloads) in [list, dict, OrderedDict]:
|
97
108
|
dupSign_start_escape = "".join(["\\\\u"+hex(ord(c))[2:].zfill(4) for c in dupSign_start])
|
98
109
|
dupSign_start_escape_regex = re.escape(dupSign_start)
|
@@ -101,23 +112,41 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
|
|
101
112
|
dupSign_end_escape_regex = re.escape(dupSign_end)
|
102
113
|
|
103
114
|
|
104
|
-
|
105
|
-
|
106
|
-
|
115
|
+
if type(Jstr) == bytes:
|
116
|
+
Jstr = re.sub(r'\\\\'.encode(), '\x00\x01'.encode(), Jstr)
|
117
|
+
Jstr = re.sub(r'\\"'.encode(), '\x02\x03'.encode(), Jstr)
|
118
|
+
Jstr = re.sub(r'"([^"]*)"[\s\t\r\n]*([,\]}])'.encode(), '\x04\x05\\1\x04\x05\\2'.encode(), Jstr)
|
107
119
|
|
108
120
|
|
109
|
-
|
121
|
+
Jstr = re.sub(r'"([^"]+)"[\s\t\r\n]*:'.encode(), r'"\1{dupSign_start}_dupSign_{dupSign_end}":'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape).encode(), Jstr)
|
122
|
+
|
123
|
+
Jstr = re.sub(r'""[\s\t\r\n]*:'.encode(), '"{dupSign_start}_dupSign_{dupSign_end}":'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape).encode(), Jstr)
|
124
|
+
|
125
|
+
i = 0
|
126
|
+
while re.search(r'{dupSign_start}_dupSign_{dupSign_end}"[\s\t\r\n]*:'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape).encode(), Jstr):
|
127
|
+
Jstr = re.sub(r'{dupSign_start}_dupSign_{dupSign_end}"[\s\t\r\n]*:'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape).encode(), (dupSign_start_escape+"_"+str(i)+"_"+dupSign_end_escape+'":').encode(), Jstr, 1)
|
128
|
+
i += 1
|
129
|
+
|
130
|
+
Jstr = re.sub('\x00\x01'.encode(), r'\\\\'.encode(), Jstr)
|
131
|
+
Jstr = re.sub('\x02\x03'.encode(), r'\\"'.encode(), Jstr)
|
132
|
+
Jstr = re.sub('\x04\x05'.encode(), r'"'.encode(), Jstr)
|
133
|
+
else:
|
134
|
+
Jstr = re.sub(r'\\\\', '\x00\x01', Jstr)
|
135
|
+
Jstr = re.sub(r'\\"', '\x02\x03', Jstr)
|
136
|
+
Jstr = re.sub(r'"([^"]*)"[\s\t\r\n]*([,\]}])', '\x04\x05\\1\x04\x05\\2', Jstr)
|
137
|
+
|
138
|
+
Jstr = re.sub(r'"([^"]+)"[\s\t\r\n]*:', r'"\1{dupSign_start}_dupSign_{dupSign_end}":'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape), Jstr)
|
110
139
|
|
111
|
-
|
140
|
+
Jstr = re.sub(r'""[\s\t\r\n]*:', '"{dupSign_start}_dupSign_{dupSign_end}":'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape), Jstr)
|
112
141
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
142
|
+
i = 0
|
143
|
+
while re.search(r'{dupSign_start}_dupSign_{dupSign_end}"[\s\t\r\n]*:'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape), Jstr):
|
144
|
+
Jstr = re.sub(r'{dupSign_start}_dupSign_{dupSign_end}"[\s\t\r\n]*:'.format(dupSign_start=dupSign_start_escape, dupSign_end=dupSign_end_escape), dupSign_start_escape+"_"+str(i)+"_"+dupSign_end_escape+'":', Jstr, 1)
|
145
|
+
i += 1
|
117
146
|
|
118
|
-
|
119
|
-
|
120
|
-
|
147
|
+
Jstr = re.sub('\x00\x01', r'\\\\', Jstr)
|
148
|
+
Jstr = re.sub('\x02\x03', r'\\"', Jstr)
|
149
|
+
Jstr = re.sub('\x04\x05', r'"', Jstr)
|
121
150
|
|
122
151
|
Jloads = json.loads(Jstr)
|
123
152
|
if ordered_dict:
|
@@ -147,15 +176,13 @@ def loads(Jstr, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isD
|
|
147
176
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
148
177
|
# # # # # # # # # # # # # # # load # # # # # # # # # # # # # #
|
149
178
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
150
|
-
def load(Jfilepath, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, _isDebug_=False):
|
179
|
+
def load(Jfilepath, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, skipDuplicated=False, _isDebug_=False):
|
151
180
|
try:
|
152
|
-
with open(Jfilepath) as Jfile:
|
153
|
-
Jstr = Jfile.read()
|
154
|
-
|
155
|
-
return loads(Jstr, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, _isDebug_=_isDebug_)
|
181
|
+
with open(Jfilepath) as Jfile: Jstr = Jfile.read()
|
156
182
|
except Exception as e:
|
157
|
-
|
158
|
-
|
183
|
+
with open(Jfilepath, "rb") as Jfile: Jstr = Jfile.read()
|
184
|
+
|
185
|
+
return loads(Jstr, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, skipDuplicated=skipDuplicated, _isDebug_=_isDebug_)
|
159
186
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
160
187
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
161
188
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
@@ -188,7 +215,7 @@ class JSON_DUPLICATE_KEYS:
|
|
188
215
|
# User input data type validation
|
189
216
|
if type(_isDebug_) != bool: _isDebug_ = False
|
190
217
|
|
191
|
-
if type(name) not in [str, unicode]:
|
218
|
+
if type(name) not in [str, unicode]:
|
192
219
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
193
220
|
return {"name":name, "value":"JSON_DUPLICATE_KEYS_ERROR"}
|
194
221
|
|
@@ -211,16 +238,18 @@ class JSON_DUPLICATE_KEYS:
|
|
211
238
|
Jname = []
|
212
239
|
Jval = self.__Jobj
|
213
240
|
name_split = name.split(separator)
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
241
|
+
|
242
|
+
if type(Jobj.getObject()) in [dict, OrderedDict]:
|
243
|
+
for k in Jobj.getObject().keys():
|
244
|
+
if len(k.split(separator)) >= len(name_split):
|
245
|
+
if case_insensitive:
|
246
|
+
if separator.join(k.split(separator)[:len(name_split)]).lower() == name.lower():
|
247
|
+
Jname = k.split(separator)[:len(name_split)]
|
248
|
+
break
|
249
|
+
else:
|
250
|
+
if separator.join(k.split(separator)[:len(name_split)]) == name:
|
251
|
+
Jname = name_split
|
252
|
+
break
|
224
253
|
|
225
254
|
if len(Jname) > 0:
|
226
255
|
for k in Jname:
|
@@ -246,7 +275,7 @@ class JSON_DUPLICATE_KEYS:
|
|
246
275
|
|
247
276
|
if type(ordered_dict) != bool: ordered_dict = False
|
248
277
|
|
249
|
-
if type(name) not in [str, unicode]:
|
278
|
+
if type(name) not in [str, unicode]:
|
250
279
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
251
280
|
return False
|
252
281
|
|
@@ -293,8 +322,12 @@ class JSON_DUPLICATE_KEYS:
|
|
293
322
|
return True
|
294
323
|
else:
|
295
324
|
if len(name.split(separator)) == 1:
|
296
|
-
self.getObject()[
|
297
|
-
|
325
|
+
if type(self.getObject()) in [dict, OrderedDict]:
|
326
|
+
self.getObject()[name] = value
|
327
|
+
return True
|
328
|
+
else:
|
329
|
+
if _isDebug_: print("\x1b[31m[-] DataTypeError: Cannot set name and value for a list object\x1b[0m")
|
330
|
+
return False
|
298
331
|
else:
|
299
332
|
if self.get(separator.join(name.split(separator)[:-1]), case_insensitive=case_insensitive, separator=separator, parse_index=parse_index)["value"] != "JSON_DUPLICATE_KEYS_ERROR":
|
300
333
|
Jget = self.get(separator.join(name.split(separator)[:-1]), case_insensitive=case_insensitive, separator=separator, parse_index=parse_index)
|
@@ -327,7 +360,7 @@ class JSON_DUPLICATE_KEYS:
|
|
327
360
|
# User input data type validation
|
328
361
|
if type(_isDebug_) != bool: _isDebug_ = False
|
329
362
|
|
330
|
-
if type(name) not in [str, unicode]:
|
363
|
+
if type(name) not in [str, unicode]:
|
331
364
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
332
365
|
return False
|
333
366
|
|
@@ -372,7 +405,7 @@ class JSON_DUPLICATE_KEYS:
|
|
372
405
|
# User input data type validation
|
373
406
|
if type(_isDebug_) != bool: _isDebug_ = False
|
374
407
|
|
375
|
-
if type(name) not in [str, unicode]:
|
408
|
+
if type(name) not in [str, unicode]:
|
376
409
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
377
410
|
return False
|
378
411
|
|
@@ -416,7 +449,7 @@ class JSON_DUPLICATE_KEYS:
|
|
416
449
|
# User input data type validation
|
417
450
|
if type(_isDebug_) != bool: _isDebug_ = False
|
418
451
|
|
419
|
-
if type(name) not in [str, unicode]:
|
452
|
+
if type(name) not in [str, unicode]:
|
420
453
|
if _isDebug_: print("\x1b[31m[-] DataTypeError: the KEY name must be str or unicode, not {}\x1b[0m".format(type(name)))
|
421
454
|
return False
|
422
455
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json-duplicate-keys
|
3
|
-
Version:
|
3
|
+
Version: 2025.7.1
|
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
|
@@ -45,8 +45,8 @@ python setup.py install
|
|
45
45
|
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
46
46
|
_Normalize Key name_
|
47
47
|
- `name`: key name
|
48
|
-
- `dupSign_start`:
|
49
|
-
- `dupSign_end`:
|
48
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
49
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
50
50
|
- `_isDebug_`: Show/ Hide debug error messages
|
51
51
|
```python
|
52
52
|
import json_duplicate_keys as jdks
|
@@ -56,12 +56,13 @@ print(jdks.normalize_key("version{{{_2_}}}"))
|
|
56
56
|
```
|
57
57
|
---
|
58
58
|
|
59
|
-
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
59
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
60
60
|
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
61
61
|
- `Jstr`: a JSON format string
|
62
|
-
- `dupSign_start`:
|
63
|
-
- `dupSign_end`:
|
62
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
63
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
64
64
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
65
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
65
66
|
- `_isDebug_`: Show/ Hide debug error messages
|
66
67
|
```python
|
67
68
|
import json_duplicate_keys as jdks
|
@@ -75,12 +76,13 @@ print(JDKSObject)
|
|
75
76
|
```
|
76
77
|
---
|
77
78
|
|
78
|
-
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
79
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `skipDuplicated`=False, `_isDebug_`=False)
|
79
80
|
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
80
81
|
- `Jfilepath`: The path to the file containing the JSON format string
|
81
|
-
- `dupSign_start`:
|
82
|
-
- `dupSign_end`:
|
82
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
83
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
83
84
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
85
|
+
- `skipDuplicated`: Skip loading duplicate keys to improve execution performance
|
84
86
|
- `_isDebug_`: Show/ Hide debug error messages
|
85
87
|
```python
|
86
88
|
# /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"}]}}
|
@@ -114,8 +116,8 @@ print(JDKSObject.getObject())
|
|
114
116
|
_Get value in the JSON object by `name`_
|
115
117
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
116
118
|
- `case_insensitive`: the key name case (in)sensitive
|
117
|
-
- `separator`:
|
118
|
-
- `parse_index`:
|
119
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
120
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
119
121
|
- `_isDebug_`: Show/ Hide debug error messages
|
120
122
|
```python
|
121
123
|
import json_duplicate_keys as jdks
|
@@ -140,10 +142,10 @@ _Set a new `name` and `value` for the JSON object_
|
|
140
142
|
- `name`: new key name for the JSON object. Supported flat key name format
|
141
143
|
- `value`: value for key `name`
|
142
144
|
- `case_insensitive`: the key name case (in)sensitive
|
143
|
-
- `separator`:
|
144
|
-
- `parse_index`:
|
145
|
-
- `dupSign_start`:
|
146
|
-
- `dupSign_end`:
|
145
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
146
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
147
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
148
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
147
149
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
148
150
|
- `_isDebug_`: Show/Hide debug error messages
|
149
151
|
```python
|
@@ -178,25 +180,6 @@ print(JDKSObject.getObject())
|
|
178
180
|
JDKSObject.set("snapshot||author", "truocphan")
|
179
181
|
print(JDKSObject.getObject())
|
180
182
|
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
181
|
-
|
182
|
-
|
183
|
-
Jstr = '[]'
|
184
|
-
JDKSObject = jdks.loads(Jstr)
|
185
|
-
|
186
|
-
print(JDKSObject.getObject())
|
187
|
-
# OUTPUT: []
|
188
|
-
|
189
|
-
JDKSObject.set("author", "truocphan")
|
190
|
-
print(JDKSObject.getObject())
|
191
|
-
# OUTPUT: [{'author': 'truocphan'}]
|
192
|
-
|
193
|
-
JDKSObject.set("release", [])
|
194
|
-
print(JDKSObject.getObject())
|
195
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
196
|
-
|
197
|
-
JDKSObject.set("$1$||release||", {"version": "latest"})
|
198
|
-
print(JDKSObject.getObject())
|
199
|
-
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
200
183
|
```
|
201
184
|
---
|
202
185
|
|
@@ -206,10 +189,10 @@ _Insert `value` at `position` in value list of `name`_
|
|
206
189
|
- `value`: new value for key `name`
|
207
190
|
- `position`: position of the `value` to insert (default insert at the last position of the list)
|
208
191
|
- `case_insensitive`: the key name case (in)sensitive
|
209
|
-
- `separator`:
|
210
|
-
- `parse_index`:
|
211
|
-
- `dupSign_start`:
|
212
|
-
- `dupSign_end`:
|
192
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
193
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
194
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
195
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
213
196
|
- `_isDebug_`: Show/ Hide debug error messages
|
214
197
|
```python
|
215
198
|
import json_duplicate_keys as jdks
|
@@ -235,10 +218,10 @@ _Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
|
235
218
|
- `value`: new value for key `name`
|
236
219
|
- `case_insensitive`: the key name case (in)sensitive
|
237
220
|
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
238
|
-
- `separator`:
|
239
|
-
- `parse_index`:
|
240
|
-
- `dupSign_start`:
|
241
|
-
- `dupSign_end`:
|
221
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
222
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
223
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
224
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
242
225
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
243
226
|
- `_isDebug_`: Show/ Hide debug error messages
|
244
227
|
```python
|
@@ -263,8 +246,8 @@ print(JDKSObject.getObject())
|
|
263
246
|
_Delete a key-value pair in a JSON object by key `name`_
|
264
247
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
265
248
|
- `case_insensitive`: the key name case (in)sensitive
|
266
|
-
- `separator`:
|
267
|
-
- `parse_index`:
|
249
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
250
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
268
251
|
- `_isDebug_`: Show/ Hide debug error messages
|
269
252
|
```python
|
270
253
|
import json_duplicate_keys as jdks
|
@@ -286,10 +269,10 @@ print(JDKSObject.getObject())
|
|
286
269
|
---
|
287
270
|
|
288
271
|
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
289
|
-
|
272
|
+
_Return a `JSON_DUPLICATE_KEYS` object with keys matching a pattern_
|
290
273
|
- `name`:
|
291
|
-
- `separator`:
|
292
|
-
- `parse_index`:
|
274
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
275
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
293
276
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
294
277
|
```python
|
295
278
|
import json_duplicate_keys as jdks
|
@@ -307,10 +290,10 @@ print(JDKSObject.dumps())
|
|
307
290
|
---
|
308
291
|
|
309
292
|
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
310
|
-
|
293
|
+
_Return a `JSON_DUPLICATE_KEYS` object with values matching a pattern_
|
311
294
|
- `value`:
|
312
|
-
- `separator`:
|
313
|
-
- `parse_index`:
|
295
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
296
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
314
297
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
315
298
|
```python
|
316
299
|
import json_duplicate_keys as jdks
|
@@ -329,8 +312,8 @@ print(JDKSObject.dumps())
|
|
329
312
|
|
330
313
|
### 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)
|
331
314
|
_Serialize a JSON object to a JSON format string_
|
332
|
-
- `dupSign_start`:
|
333
|
-
- `dupSign_end`:
|
315
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
316
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
334
317
|
- `_isDebug_`: Show/ Hide debug error messages
|
335
318
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
336
319
|
```python
|
@@ -355,8 +338,8 @@ print(JDKSObject.dumps())
|
|
355
338
|
### 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)
|
356
339
|
_Serialize a JSON object to a JSON format string and write to a file_
|
357
340
|
- `Jfilepath`: the path to the file to save the JSON format string
|
358
|
-
- `dupSign_start`:
|
359
|
-
- `dupSign_end`:
|
341
|
+
- `dupSign_start`: Start symbol for marking duplicates (default: `{{{`)
|
342
|
+
- `dupSign_end`: End symbol for marking duplicates (default: `}}}`)
|
360
343
|
- `_isDebug_`: Show/ Hide debug error messages
|
361
344
|
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
362
345
|
```python
|
@@ -384,8 +367,8 @@ print(JDKSObject_load.getObject())
|
|
384
367
|
|
385
368
|
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
386
369
|
_Flatten a JSON object to a single key-value pairs_
|
387
|
-
- `separator`:
|
388
|
-
- `parse_index`:
|
370
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
371
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
389
372
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
390
373
|
- `_isDebug_`: Show/ Hide debug error messages
|
391
374
|
```python
|
@@ -407,8 +390,8 @@ print(JDKSObject.getObject())
|
|
407
390
|
|
408
391
|
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
409
392
|
_Unflatten a flattened JSON object back to a JSON object_
|
410
|
-
- `separator`:
|
411
|
-
- `parse_index`:
|
393
|
+
- `separator`: Separator for flatten keys (default: `||`)
|
394
|
+
- `parse_index`: Symbol for index parsing (default: `$`)
|
412
395
|
- `ordered_dict`: preserves the order in which the Keys are inserted
|
413
396
|
- `_isDebug_`: Show/ Hide debug error messages
|
414
397
|
```python
|
@@ -429,6 +412,14 @@ print(JDKSObject.getObject())
|
|
429
412
|
---
|
430
413
|
|
431
414
|
## CHANGELOG
|
415
|
+
#### [json-duplicate-keys v2025.7.1](https://github.com/truocphan/json-duplicate-keys/tree/2025.7.1)
|
416
|
+
- [**Updated**] Fixed some issues when loading JSON strings with `skipDuplicated` option
|
417
|
+
- [**Updated**] Allow loading of JSON data in byte string format
|
418
|
+
- [**Updated**] Issue with getting and setting an empty list
|
419
|
+
|
420
|
+
#### [json-duplicate-keys v2025.6.6](https://github.com/truocphan/json-duplicate-keys/tree/2025.6.6)
|
421
|
+
- [**Updated**] Added `skipDuplicated` parameter to `load` and `loads` functions to improve performance when parsing large JSON strings by skipping duplicate keys.
|
422
|
+
|
432
423
|
#### [json-duplicate-keys v2024.12.12](https://github.com/truocphan/json-duplicate-keys/tree/2024.12.12)
|
433
424
|
- **New**: _insert_ function
|
434
425
|
|
@@ -1,8 +1,9 @@
|
|
1
|
+
from json_duplicate_keys import json_duplicate_keys_VERSION
|
1
2
|
import setuptools
|
2
3
|
|
3
4
|
setuptools.setup(
|
4
5
|
name="json-duplicate-keys",
|
5
|
-
version=
|
6
|
+
version=json_duplicate_keys_VERSION,
|
6
7
|
author="TP Cyber Security",
|
7
8
|
license="MIT",
|
8
9
|
author_email="tpcybersec2023@gmail.com",
|
@@ -17,5 +18,5 @@ setuptools.setup(
|
|
17
18
|
"Programming Language :: Python :: Implementation :: Jython"
|
18
19
|
],
|
19
20
|
keywords=["TPCyberSec", "json", "duplicate keys", "json duplicate keys", "flatten", "unflatten"],
|
20
|
-
packages=
|
21
|
+
packages=setuptools.find_packages(),
|
21
22
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|