json-duplicate-keys 2024.11.19__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.
@@ -0,0 +1,450 @@
1
+ Metadata-Version: 2.1
2
+ Name: json-duplicate-keys
3
+ Version: 2024.12.12
4
+ Summary: Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
5
+ Home-page: https://github.com/truocphan/json-duplicate-keys
6
+ Author: TP Cyber Security
7
+ Author-email: tpcybersec2023@gmail.com
8
+ License: MIT
9
+ Keywords: TPCyberSec,json,duplicate keys,json duplicate keys,flatten,unflatten
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 2
12
+ Classifier: Programming Language :: Python :: Implementation :: Jython
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # JSON Duplicate Keys - PyPI
17
+ Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
18
+
19
+ <p align="center">
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
+ <a href="#"><img src="https://img.shields.io/github/downloads/truocphan/json-duplicate-keys/total" height=30></a>
22
+ <a href="#"><img src="https://img.shields.io/github/stars/truocphan/json-duplicate-keys" height=30></a>
23
+ <a href="#"><img src="https://img.shields.io/github/forks/truocphan/json-duplicate-keys" height=30></a>
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
+ <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>
29
+ </p>
30
+
31
+ ## Installation
32
+ #### From PyPI:
33
+ ```console
34
+ pip install json-duplicate-keys
35
+ ```
36
+ #### From Source:
37
+ ```console
38
+ git clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>
39
+ cd json-duplicate-keys
40
+ python setup.py build
41
+ python setup.py install
42
+ ```
43
+
44
+ ## Basic Usage
45
+ ### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
46
+ _Normalize Key name_
47
+ - `name`: key name
48
+ - `dupSign_start`:
49
+ - `dupSign_end`:
50
+ - `_isDebug_`: Show/ Hide debug error messages
51
+ ```python
52
+ import json_duplicate_keys as jdks
53
+
54
+ print(jdks.normalize_key("version{{{_2_}}}"))
55
+ # OUTPUT: version
56
+ ```
57
+ ---
58
+
59
+ ### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
60
+ _Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
61
+ - `Jstr`: a JSON format string
62
+ - `dupSign_start`:
63
+ - `dupSign_end`:
64
+ - `ordered_dict`: preserves the order in which the Keys are inserted
65
+ - `_isDebug_`: Show/ Hide debug error messages
66
+ ```python
67
+ import json_duplicate_keys as jdks
68
+
69
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
70
+
71
+ JDKSObject = jdks.loads(Jstr)
72
+
73
+ print(JDKSObject)
74
+ # OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>
75
+ ```
76
+ ---
77
+
78
+ ### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
79
+ _Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
80
+ - `Jfilepath`: The path to the file containing the JSON format string
81
+ - `dupSign_start`:
82
+ - `dupSign_end`:
83
+ - `ordered_dict`: preserves the order in which the Keys are inserted
84
+ - `_isDebug_`: Show/ Hide debug error messages
85
+ ```python
86
+ # /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"}]}}
87
+
88
+ import json_duplicate_keys as jdks
89
+
90
+ Jfilepath = "/path/to/file.json"
91
+
92
+ JDKSObject = jdks.load(Jfilepath)
93
+
94
+ print(JDKSObject)
95
+ # OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>
96
+ ```
97
+ ---
98
+
99
+ ### JSON_DUPLICATE_KEYS.getObject()
100
+ _Get the JSON object_
101
+ ```python
102
+ import json_duplicate_keys as jdks
103
+
104
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
105
+
106
+ JDKSObject = jdks.loads(Jstr)
107
+
108
+ print(JDKSObject.getObject())
109
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
110
+ ```
111
+ ---
112
+
113
+ ### JSON_DUPLICATE_KEYS.get(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
114
+ _Get value in the JSON object by `name`_
115
+ - `name`: the key name of the JSON object. Supported flatten key name format
116
+ - `case_insensitive`: the key name case (in)sensitive
117
+ - `separator`:
118
+ - `parse_index`:
119
+ - `_isDebug_`: Show/ Hide debug error messages
120
+ ```python
121
+ import json_duplicate_keys as jdks
122
+
123
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
124
+
125
+ JDKSObject = jdks.loads(Jstr)
126
+
127
+ print(JDKSObject.get("version{{{_2_}}}"))
128
+ # OUTPUT: {'name': 'version{{{_2_}}}', 'value': 'latest'}
129
+
130
+ print(JDKSObject.get("release||$0$"))
131
+ # OUTPUT: {'name': 'release||$0$', 'value': {'version': 'latest'}}
132
+
133
+ print(JDKSObject.get("snapshot||author"))
134
+ # OUTPUT: {'name': 'snapshot||author', 'value': 'truocphan'}
135
+ ```
136
+ ---
137
+
138
+ ### JSON_DUPLICATE_KEYS.set(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
139
+ _Set a new `name` and `value` for the JSON object_
140
+ - `name`: new key name for the JSON object. Supported flat key name format
141
+ - `value`: value for key `name`
142
+ - `case_insensitive`: the key name case (in)sensitive
143
+ - `separator`:
144
+ - `parse_index`:
145
+ - `dupSign_start`:
146
+ - `dupSign_end`:
147
+ - `ordered_dict`: preserves the order in which the Keys are inserted
148
+ - `_isDebug_`: Show/Hide debug error messages
149
+ ```python
150
+ import json_duplicate_keys as jdks
151
+
152
+ Jstr = '{}'
153
+ JDKSObject = jdks.loads(Jstr)
154
+
155
+ print(JDKSObject.getObject())
156
+ # OUTPUT: {}
157
+
158
+ JDKSObject.set("author", "truocphan")
159
+ print(JDKSObject.getObject())
160
+ # OUTPUT: {'author': 'truocphan'}
161
+
162
+ JDKSObject.set("version", "22.3.3")
163
+ print(JDKSObject.getObject())
164
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}
165
+
166
+ JDKSObject.set("version", "latest")
167
+ print(JDKSObject.getObject())
168
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}
169
+
170
+ JDKSObject.set("release", [{"version": "latest"}])
171
+ print(JDKSObject.getObject())
172
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}
173
+
174
+ JDKSObject.set("snapshot", {})
175
+ print(JDKSObject.getObject())
176
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}
177
+
178
+ JDKSObject.set("snapshot||author", "truocphan")
179
+ print(JDKSObject.getObject())
180
+ # 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
+ ```
201
+ ---
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
+
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)
233
+ _Update new `value` for existing `name` or Set a new `name` in the JSON object_
234
+ - `name`: the key name of the JSON object. Supported flatten key name format
235
+ - `value`: new value for key `name`
236
+ - `case_insensitive`: the key name case (in)sensitive
237
+ - `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`:
242
+ - `ordered_dict`: preserves the order in which the Keys are inserted
243
+ - `_isDebug_`: Show/ Hide debug error messages
244
+ ```python
245
+ import json_duplicate_keys as jdks
246
+
247
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
248
+
249
+ JDKSObject = jdks.loads(Jstr)
250
+
251
+ print(JDKSObject.getObject())
252
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
253
+
254
+ JDKSObject.update("version{{{_2_}}}", ["22.3.3", "latest"])
255
+ JDKSObject.update("snapshot||version", "latest")
256
+
257
+ print(JDKSObject.getObject())
258
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}
259
+ ```
260
+ ---
261
+
262
+ ### JSON_DUPLICATE_KEYS.delete(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
263
+ _Delete a key-value pair in a JSON object by key `name`_
264
+ - `name`: the key name of the JSON object. Supported flatten key name format
265
+ - `case_insensitive`: the key name case (in)sensitive
266
+ - `separator`:
267
+ - `parse_index`:
268
+ - `_isDebug_`: Show/ Hide debug error messages
269
+ ```python
270
+ import json_duplicate_keys as jdks
271
+
272
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
273
+
274
+ JDKSObject = jdks.loads(Jstr)
275
+
276
+ print(JDKSObject.getObject())
277
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
278
+
279
+ JDKSObject.delete("version")
280
+ JDKSObject.delete("release||$0$")
281
+ JDKSObject.delete("snapshot")
282
+
283
+ print(JDKSObject.getObject())
284
+ # OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}
285
+ ```
286
+ ---
287
+
288
+ ### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
289
+
290
+ - `name`:
291
+ - `separator`:
292
+ - `parse_index`:
293
+ - `ordered_dict`: preserves the order in which the Keys are inserted
294
+ ```python
295
+ import json_duplicate_keys as jdks
296
+
297
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
298
+
299
+ JDKSObject = jdks.loads(Jstr)
300
+
301
+ print(JDKSObject.filter_keys("version").dumps())
302
+ # OUTPUT: {"version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}
303
+
304
+ print(JDKSObject.dumps())
305
+ # OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
306
+ ```
307
+ ---
308
+
309
+ ### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
310
+
311
+ - `value`:
312
+ - `separator`:
313
+ - `parse_index`:
314
+ - `ordered_dict`: preserves the order in which the Keys are inserted
315
+ ```python
316
+ import json_duplicate_keys as jdks
317
+
318
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
319
+
320
+ JDKSObject = jdks.loads(Jstr)
321
+
322
+ print(JDKSObject.filter_values("latest").dumps())
323
+ # OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
324
+
325
+ print(JDKSObject.dumps())
326
+ # OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
327
+ ```
328
+ ---
329
+
330
+ ### 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
+ _Serialize a JSON object to a JSON format string_
332
+ - `dupSign_start`:
333
+ - `dupSign_end`:
334
+ - `_isDebug_`: Show/ Hide debug error messages
335
+ - For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
336
+ ```python
337
+ import json_duplicate_keys as jdks
338
+
339
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
340
+
341
+ JDKSObject = jdks.loads(Jstr)
342
+
343
+ print(JDKSObject.getObject())
344
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
345
+
346
+ JDKSObject.delete("version")
347
+ JDKSObject.delete("release||$0$")
348
+ JDKSObject.delete("snapshot")
349
+
350
+ print(JDKSObject.dumps())
351
+ # OUTPUT: {"author": "truocphan", "version": "latest", "release": []}
352
+ ```
353
+ ---
354
+
355
+ ### 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
+ _Serialize a JSON object to a JSON format string and write to a file_
357
+ - `Jfilepath`: the path to the file to save the JSON format string
358
+ - `dupSign_start`:
359
+ - `dupSign_end`:
360
+ - `_isDebug_`: Show/ Hide debug error messages
361
+ - For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
362
+ ```python
363
+ import json_duplicate_keys as jdks
364
+
365
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
366
+
367
+ JDKSObject = jdks.loads(Jstr)
368
+
369
+ print(JDKSObject.getObject())
370
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
371
+
372
+ JDKSObject.delete("version")
373
+ JDKSObject.delete("release||$0$")
374
+ JDKSObject.delete("snapshot")
375
+
376
+ Jfilepath = "/path/to/file.json"
377
+ JDKSObject.dump(Jfilepath)
378
+
379
+ JDKSObject_load = jdks.load(Jfilepath)
380
+ print(JDKSObject_load.getObject())
381
+ # OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}
382
+ ```
383
+ ---
384
+
385
+ ### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
386
+ _Flatten a JSON object to a single key-value pairs_
387
+ - `separator`:
388
+ - `parse_index`:
389
+ - `ordered_dict`: preserves the order in which the Keys are inserted
390
+ - `_isDebug_`: Show/ Hide debug error messages
391
+ ```python
392
+ import json_duplicate_keys as jdks
393
+
394
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
395
+
396
+ JDKSObject = jdks.loads(Jstr)
397
+
398
+ print(JDKSObject.getObject())
399
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
400
+
401
+ JDKSObject.flatten()
402
+
403
+ print(JDKSObject.getObject())
404
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}
405
+ ```
406
+ ---
407
+
408
+ ### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
409
+ _Unflatten a flattened JSON object back to a JSON object_
410
+ - `separator`:
411
+ - `parse_index`:
412
+ - `ordered_dict`: preserves the order in which the Keys are inserted
413
+ - `_isDebug_`: Show/ Hide debug error messages
414
+ ```python
415
+ import json_duplicate_keys as jdks
416
+
417
+ Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||author": "truocphan", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}'
418
+
419
+ JDKSObject = jdks.loads(Jstr)
420
+
421
+ print(JDKSObject.getObject())
422
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release||$0$||version': 'latest', 'snapshot||author': 'truocphan', 'snapshot||version': '22.3.3', 'snapshot||release||$0$||version': 'latest'}
423
+
424
+ JDKSObject.unflatten()
425
+
426
+ print(JDKSObject.getObject())
427
+ # OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
428
+ ```
429
+ ---
430
+
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
+
435
+ #### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
436
+ - **Fixed**: Add subkey name to empty dict of existing key name
437
+
438
+ #### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
439
+ - **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
440
+
441
+ #### [json-duplicate-keys v2024.7.17](https://github.com/truocphan/json-duplicate-keys/tree/2024.7.17)
442
+ - **Fixed**: issue [#3](https://github.com/truocphan/json-duplicate-keys/issues/3) break the set function when the key's value is empty. Thanks [ptth222](https://github.com/ptth222) for reporting this issue.
443
+
444
+ #### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
445
+ - **New**: _filter_values_
446
+ - **Updated**: _filter_keys_
447
+
448
+ #### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
449
+ - **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
450
+ ---
@@ -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
- <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>
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,13 +185,46 @@ print(JDKSObject.getObject())
182
185
  ```
183
186
  ---
184
187
 
185
- ### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
186
- _Update new `value` for existing `name` in the JSON object_
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`_
187
190
  - `name`: the key name of the JSON object. Supported flatten key name format
188
191
  - `value`: new value for key `name`
192
+ - `position`: position of the `value` to insert (default insert at the last position of the list)
189
193
  - `case_insensitive`: the key name case (in)sensitive
190
194
  - `separator`:
191
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
+
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)
218
+ _Update new `value` for existing `name` or Set a new `name` in the JSON object_
219
+ - `name`: the key name of the JSON object. Supported flatten key name format
220
+ - `value`: new value for key `name`
221
+ - `case_insensitive`: the key name case (in)sensitive
222
+ - `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`:
227
+ - `ordered_dict`: preserves the order in which the Keys are inserted
192
228
  - `_isDebug_`: Show/ Hide debug error messages
193
229
  ```python
194
230
  import json_duplicate_keys as jdks
@@ -239,7 +275,7 @@ print(JDKSObject.getObject())
239
275
  - `name`:
240
276
  - `separator`:
241
277
  - `parse_index`:
242
- - `ordered_dict`:
278
+ - `ordered_dict`: preserves the order in which the Keys are inserted
243
279
  ```python
244
280
  import json_duplicate_keys as jdks
245
281
 
@@ -260,7 +296,7 @@ print(JDKSObject.dumps())
260
296
  - `value`:
261
297
  - `separator`:
262
298
  - `parse_index`:
263
- - `ordered_dict`:
299
+ - `ordered_dict`: preserves the order in which the Keys are inserted
264
300
  ```python
265
301
  import json_duplicate_keys as jdks
266
302
 
@@ -378,6 +414,12 @@ print(JDKSObject.getObject())
378
414
  ---
379
415
 
380
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
+
420
+ #### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
421
+ - **Fixed**: Add subkey name to empty dict of existing key name
422
+
381
423
  #### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
382
424
  - **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
383
425