json-duplicate-keys 2024.7.17__tar.gz → 2024.11.28__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.7.17 → json_duplicate_keys-2024.11.28}/LICENSE +0 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/MANIFEST.in +0 -0
- json_duplicate_keys-2024.11.28/PKG-INFO +415 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/README.md +21 -13
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/json_duplicate_keys/__init__.py +140 -212
- json_duplicate_keys-2024.11.28/json_duplicate_keys.egg-info/PKG-INFO +415 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/json_duplicate_keys.egg-info/SOURCES.txt +0 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/json_duplicate_keys.egg-info/dependency_links.txt +0 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/json_duplicate_keys.egg-info/top_level.txt +0 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/requirements.txt +0 -0
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/setup.cfg +4 -4
- {json-duplicate-keys-2024.7.17 → json_duplicate_keys-2024.11.28}/setup.py +1 -1
- json-duplicate-keys-2024.7.17/PKG-INFO +0 -406
- json-duplicate-keys-2024.7.17/json_duplicate_keys.egg-info/PKG-INFO +0 -406
File without changes
|
File without changes
|
@@ -0,0 +1,415 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: json-duplicate-keys
|
3
|
+
Version: 2024.11.28
|
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
|
+
</p>
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
#### From PyPI:
|
30
|
+
```console
|
31
|
+
pip install json-duplicate-keys
|
32
|
+
```
|
33
|
+
#### From Source:
|
34
|
+
```console
|
35
|
+
git clone https://github.com/truocphan/json-duplicate-keys.git --branch <Branch/Tag>
|
36
|
+
cd json-duplicate-keys
|
37
|
+
python setup.py build
|
38
|
+
python setup.py install
|
39
|
+
```
|
40
|
+
|
41
|
+
## Basic Usage
|
42
|
+
### normalize_key(`name`, `dupSign_start`="{{{", `dupSign_end`="}}}", `_isDebug_`=False)
|
43
|
+
_Normalize Key name_
|
44
|
+
- `name`: key name
|
45
|
+
- `dupSign_start`:
|
46
|
+
- `dupSign_end`:
|
47
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
48
|
+
```python
|
49
|
+
import json_duplicate_keys as jdks
|
50
|
+
|
51
|
+
print(jdks.normalize_key("version{{{_2_}}}"))
|
52
|
+
# OUTPUT: version
|
53
|
+
```
|
54
|
+
---
|
55
|
+
|
56
|
+
### loads(`Jstr`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
57
|
+
_Deserialize a JSON format string to a class `JSON_DUPLICATE_KEYS`_
|
58
|
+
- `Jstr`: a JSON format string
|
59
|
+
- `dupSign_start`:
|
60
|
+
- `dupSign_end`:
|
61
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
62
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
63
|
+
```python
|
64
|
+
import json_duplicate_keys as jdks
|
65
|
+
|
66
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
67
|
+
|
68
|
+
JDKSObject = jdks.loads(Jstr)
|
69
|
+
|
70
|
+
print(JDKSObject)
|
71
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE987940>
|
72
|
+
```
|
73
|
+
---
|
74
|
+
|
75
|
+
### load(`Jfilepath`, `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
76
|
+
_Deserialize a JSON format string from a file to a class `JSON_DUPLICATE_KEYS`_
|
77
|
+
- `Jfilepath`: The path to the file containing the JSON format string
|
78
|
+
- `dupSign_start`:
|
79
|
+
- `dupSign_end`:
|
80
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
81
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
82
|
+
```python
|
83
|
+
# /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"}]}}
|
84
|
+
|
85
|
+
import json_duplicate_keys as jdks
|
86
|
+
|
87
|
+
Jfilepath = "/path/to/file.json"
|
88
|
+
|
89
|
+
JDKSObject = jdks.load(Jfilepath)
|
90
|
+
|
91
|
+
print(JDKSObject)
|
92
|
+
# OUTPUT: <json_duplicate_keys.JSON_DUPLICATE_KEYS object at 0x00000270AE986D40>
|
93
|
+
```
|
94
|
+
---
|
95
|
+
|
96
|
+
### JSON_DUPLICATE_KEYS.getObject()
|
97
|
+
_Get the JSON object_
|
98
|
+
```python
|
99
|
+
import json_duplicate_keys as jdks
|
100
|
+
|
101
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
102
|
+
|
103
|
+
JDKSObject = jdks.loads(Jstr)
|
104
|
+
|
105
|
+
print(JDKSObject.getObject())
|
106
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
107
|
+
```
|
108
|
+
---
|
109
|
+
|
110
|
+
### JSON_DUPLICATE_KEYS.get(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
111
|
+
_Get value in the JSON object by `name`_
|
112
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
113
|
+
- `case_insensitive`: the key name case (in)sensitive
|
114
|
+
- `separator`:
|
115
|
+
- `parse_index`:
|
116
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
117
|
+
```python
|
118
|
+
import json_duplicate_keys as jdks
|
119
|
+
|
120
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
121
|
+
|
122
|
+
JDKSObject = jdks.loads(Jstr)
|
123
|
+
|
124
|
+
print(JDKSObject.get("version{{{_2_}}}"))
|
125
|
+
# OUTPUT: latest
|
126
|
+
|
127
|
+
print(JDKSObject.get("release||$0$"))
|
128
|
+
# OUTPUT: {'version': 'latest'}
|
129
|
+
|
130
|
+
print(JDKSObject.get("snapshot||author"))
|
131
|
+
# OUTPUT: truocphan
|
132
|
+
```
|
133
|
+
---
|
134
|
+
|
135
|
+
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
136
|
+
_Set a new `name` and `value` for the JSON object_
|
137
|
+
- `name`: new key name for the JSON object. Supported flat key name format
|
138
|
+
- `value`: value for key `name`
|
139
|
+
- `case_insensitive`: the key name case (in)sensitive
|
140
|
+
- `separator`:
|
141
|
+
- `parse_index`:
|
142
|
+
- `dupSign_start`:
|
143
|
+
- `dupSign_end`:
|
144
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
145
|
+
- `_isDebug_`: Show/Hide debug error messages
|
146
|
+
```python
|
147
|
+
import json_duplicate_keys as jdks
|
148
|
+
|
149
|
+
Jstr = '{}'
|
150
|
+
JDKSObject = jdks.loads(Jstr)
|
151
|
+
|
152
|
+
print(JDKSObject.getObject())
|
153
|
+
# OUTPUT: {}
|
154
|
+
|
155
|
+
JDKSObject.set("author", "truocphan")
|
156
|
+
print(JDKSObject.getObject())
|
157
|
+
# OUTPUT: {'author': 'truocphan'}
|
158
|
+
|
159
|
+
JDKSObject.set("version", "22.3.3")
|
160
|
+
print(JDKSObject.getObject())
|
161
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3'}
|
162
|
+
|
163
|
+
JDKSObject.set("version", "latest")
|
164
|
+
print(JDKSObject.getObject())
|
165
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest'}
|
166
|
+
|
167
|
+
JDKSObject.set("release", [{"version": "latest"}])
|
168
|
+
print(JDKSObject.getObject())
|
169
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}]}
|
170
|
+
|
171
|
+
JDKSObject.set("snapshot", {})
|
172
|
+
print(JDKSObject.getObject())
|
173
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {}}
|
174
|
+
|
175
|
+
JDKSObject.set("snapshot||author", "truocphan")
|
176
|
+
print(JDKSObject.getObject())
|
177
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan'}}
|
178
|
+
|
179
|
+
|
180
|
+
Jstr = '[]'
|
181
|
+
JDKSObject = jdks.loads(Jstr)
|
182
|
+
|
183
|
+
print(JDKSObject.getObject())
|
184
|
+
# OUTPUT: []
|
185
|
+
|
186
|
+
JDKSObject.set("author", "truocphan")
|
187
|
+
print(JDKSObject.getObject())
|
188
|
+
# OUTPUT: [{'author': 'truocphan'}]
|
189
|
+
|
190
|
+
JDKSObject.set("release", [])
|
191
|
+
print(JDKSObject.getObject())
|
192
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': []}]
|
193
|
+
|
194
|
+
JDKSObject.set("$1$||release||", {"version": "latest"})
|
195
|
+
print(JDKSObject.getObject())
|
196
|
+
# OUTPUT: [{'author': 'truocphan'}, {'release': [{'version': 'latest'}]}]
|
197
|
+
```
|
198
|
+
---
|
199
|
+
|
200
|
+
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `allow_new_key`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
201
|
+
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
202
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
203
|
+
- `value`: new value for key `name`
|
204
|
+
- `case_insensitive`: the key name case (in)sensitive
|
205
|
+
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
206
|
+
- `separator`:
|
207
|
+
- `parse_index`:
|
208
|
+
- `dupSign_start`:
|
209
|
+
- `dupSign_end`:
|
210
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
211
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
212
|
+
```python
|
213
|
+
import json_duplicate_keys as jdks
|
214
|
+
|
215
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
216
|
+
|
217
|
+
JDKSObject = jdks.loads(Jstr)
|
218
|
+
|
219
|
+
print(JDKSObject.getObject())
|
220
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
221
|
+
|
222
|
+
JDKSObject.update("version{{{_2_}}}", ["22.3.3", "latest"])
|
223
|
+
JDKSObject.update("snapshot||version", "latest")
|
224
|
+
|
225
|
+
print(JDKSObject.getObject())
|
226
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': ['22.3.3', 'latest'], 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': 'latest', 'release': [{'version': 'latest'}]}}
|
227
|
+
```
|
228
|
+
---
|
229
|
+
|
230
|
+
### JSON_DUPLICATE_KEYS.delete(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
231
|
+
_Delete a key-value pair in a JSON object by key `name`_
|
232
|
+
- `name`: the key name of the JSON object. Supported flatten key name format
|
233
|
+
- `case_insensitive`: the key name case (in)sensitive
|
234
|
+
- `separator`:
|
235
|
+
- `parse_index`:
|
236
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
237
|
+
```python
|
238
|
+
import json_duplicate_keys as jdks
|
239
|
+
|
240
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
241
|
+
|
242
|
+
JDKSObject = jdks.loads(Jstr)
|
243
|
+
|
244
|
+
print(JDKSObject.getObject())
|
245
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
246
|
+
|
247
|
+
JDKSObject.delete("version")
|
248
|
+
JDKSObject.delete("release||$0$")
|
249
|
+
JDKSObject.delete("snapshot")
|
250
|
+
|
251
|
+
print(JDKSObject.getObject())
|
252
|
+
# OUTPUT: {'author': 'truocphan', 'version{{{_2_}}}': 'latest', 'release': []}
|
253
|
+
```
|
254
|
+
---
|
255
|
+
|
256
|
+
### JSON_DUPLICATE_KEYS.filter_keys(`name`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
257
|
+
|
258
|
+
- `name`:
|
259
|
+
- `separator`:
|
260
|
+
- `parse_index`:
|
261
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
262
|
+
```python
|
263
|
+
import json_duplicate_keys as jdks
|
264
|
+
|
265
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
266
|
+
|
267
|
+
JDKSObject = jdks.loads(Jstr)
|
268
|
+
|
269
|
+
print(JDKSObject.filter_keys("version").dumps())
|
270
|
+
# OUTPUT: {"version": "22.3.3", "version": "latest", "release||$0$||version": "latest", "snapshot||version": "22.3.3", "snapshot||release||$0$||version": "latest"}
|
271
|
+
|
272
|
+
print(JDKSObject.dumps())
|
273
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
274
|
+
```
|
275
|
+
---
|
276
|
+
|
277
|
+
### JSON_DUPLICATE_KEYS.filter_values(`value`, `separator`="||", `parse_index`="$", `ordered_dict`=False)
|
278
|
+
|
279
|
+
- `value`:
|
280
|
+
- `separator`:
|
281
|
+
- `parse_index`:
|
282
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
283
|
+
```python
|
284
|
+
import json_duplicate_keys as jdks
|
285
|
+
|
286
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
287
|
+
|
288
|
+
JDKSObject = jdks.loads(Jstr)
|
289
|
+
|
290
|
+
print(JDKSObject.filter_values("latest").dumps())
|
291
|
+
# OUTPUT: {"version": "latest", "release||$0$||version": "latest", "snapshot||release||$0$||version": "latest"}
|
292
|
+
|
293
|
+
print(JDKSObject.dumps())
|
294
|
+
# OUTPUT: {"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}
|
295
|
+
```
|
296
|
+
---
|
297
|
+
|
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)
|
299
|
+
_Serialize a JSON object to a JSON format string_
|
300
|
+
- `dupSign_start`:
|
301
|
+
- `dupSign_end`:
|
302
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
303
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
304
|
+
```python
|
305
|
+
import json_duplicate_keys as jdks
|
306
|
+
|
307
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
308
|
+
|
309
|
+
JDKSObject = jdks.loads(Jstr)
|
310
|
+
|
311
|
+
print(JDKSObject.getObject())
|
312
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
313
|
+
|
314
|
+
JDKSObject.delete("version")
|
315
|
+
JDKSObject.delete("release||$0$")
|
316
|
+
JDKSObject.delete("snapshot")
|
317
|
+
|
318
|
+
print(JDKSObject.dumps())
|
319
|
+
# OUTPUT: {"author": "truocphan", "version": "latest", "release": []}
|
320
|
+
```
|
321
|
+
---
|
322
|
+
|
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)
|
324
|
+
_Serialize a JSON object to a JSON format string and write to a file_
|
325
|
+
- `Jfilepath`: the path to the file to save the JSON format string
|
326
|
+
- `dupSign_start`:
|
327
|
+
- `dupSign_end`:
|
328
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
329
|
+
- For remaining arguments, please refer to [json.dump()](https://docs.python.org/3/library/json.html#json.dump)
|
330
|
+
```python
|
331
|
+
import json_duplicate_keys as jdks
|
332
|
+
|
333
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
334
|
+
|
335
|
+
JDKSObject = jdks.loads(Jstr)
|
336
|
+
|
337
|
+
print(JDKSObject.getObject())
|
338
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
339
|
+
|
340
|
+
JDKSObject.delete("version")
|
341
|
+
JDKSObject.delete("release||$0$")
|
342
|
+
JDKSObject.delete("snapshot")
|
343
|
+
|
344
|
+
Jfilepath = "/path/to/file.json"
|
345
|
+
JDKSObject.dump(Jfilepath)
|
346
|
+
|
347
|
+
JDKSObject_load = jdks.load(Jfilepath)
|
348
|
+
print(JDKSObject_load.getObject())
|
349
|
+
# OUTPUT: {'author': 'truocphan', 'version': 'latest', 'release': []}
|
350
|
+
```
|
351
|
+
---
|
352
|
+
|
353
|
+
### JSON_DUPLICATE_KEYS.flatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
354
|
+
_Flatten a JSON object to a single key-value pairs_
|
355
|
+
- `separator`:
|
356
|
+
- `parse_index`:
|
357
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
358
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
359
|
+
```python
|
360
|
+
import json_duplicate_keys as jdks
|
361
|
+
|
362
|
+
Jstr = '{"author": "truocphan", "version": "22.3.3", "version": "latest", "release": [{"version": "latest"}], "snapshot": {"author": "truocphan", "version": "22.3.3", "release": [{"version": "latest"}]}}'
|
363
|
+
|
364
|
+
JDKSObject = jdks.loads(Jstr)
|
365
|
+
|
366
|
+
print(JDKSObject.getObject())
|
367
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
368
|
+
|
369
|
+
JDKSObject.flatten()
|
370
|
+
|
371
|
+
print(JDKSObject.getObject())
|
372
|
+
# 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'}
|
373
|
+
```
|
374
|
+
---
|
375
|
+
|
376
|
+
### JSON_DUPLICATE_KEYS.unflatten(`separator`="||", `parse_index`="$", `ordered_dict`=False, `_isDebug_`=False)
|
377
|
+
_Unflatten a flattened JSON object back to a JSON object_
|
378
|
+
- `separator`:
|
379
|
+
- `parse_index`:
|
380
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
381
|
+
- `_isDebug_`: Show/ Hide debug error messages
|
382
|
+
```python
|
383
|
+
import json_duplicate_keys as jdks
|
384
|
+
|
385
|
+
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"}'
|
386
|
+
|
387
|
+
JDKSObject = jdks.loads(Jstr)
|
388
|
+
|
389
|
+
print(JDKSObject.getObject())
|
390
|
+
# 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'}
|
391
|
+
|
392
|
+
JDKSObject.unflatten()
|
393
|
+
|
394
|
+
print(JDKSObject.getObject())
|
395
|
+
# OUTPUT: {'author': 'truocphan', 'version': '22.3.3', 'version{{{_2_}}}': 'latest', 'release': [{'version': 'latest'}], 'snapshot': {'author': 'truocphan', 'version': '22.3.3', 'release': [{'version': 'latest'}]}}
|
396
|
+
```
|
397
|
+
---
|
398
|
+
|
399
|
+
## CHANGELOG
|
400
|
+
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
401
|
+
- **Fixed**: Add subkey name to empty dict of existing key name
|
402
|
+
|
403
|
+
#### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
|
404
|
+
- **Updated**: Allows getting (`JSON_DUPLICATE_KEYS.get`), setting (`JSON_DUPLICATE_KEYS.set`), updating (`JSON_DUPLICATE_KEYS.update`), deleting (`JSON_DUPLICATE_KEYS.delete`) JSON_DUPLICATE_KEYS objects with case-insensitive key names
|
405
|
+
|
406
|
+
#### [json-duplicate-keys v2024.7.17](https://github.com/truocphan/json-duplicate-keys/tree/2024.7.17)
|
407
|
+
- **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.
|
408
|
+
|
409
|
+
#### [json-duplicate-keys v2024.4.20](https://github.com/truocphan/json-duplicate-keys/tree/2024.4.20)
|
410
|
+
- **New**: _filter_values_
|
411
|
+
- **Updated**: _filter_keys_
|
412
|
+
|
413
|
+
#### [json-duplicate-keys v2024.3.24](https://github.com/truocphan/json-duplicate-keys/tree/2024.3.24)
|
414
|
+
- **Updated**: _normalize_key_, _loads_, _get_, _set_, _update_, _delete_
|
415
|
+
---
|
@@ -8,12 +8,6 @@ Flatten/ Unflatten and Load(s)/ Dump(s) JSON File/ Object with Duplicate Keys
|
|
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
|
-
<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>
|
12
|
-
<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>
|
13
|
-
<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>
|
14
|
-
<a href="https://github.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white" height=30></a>
|
15
|
-
<a href="mailto:tpcybersec2023@gmail.com" target="_blank"><img src="https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white" height=30></a>
|
16
|
-
<a href="https://www.buymeacoffee.com/truocphan" target="_blank"><img src="https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black" height=30></a>
|
17
11
|
</p>
|
18
12
|
|
19
13
|
## Installation
|
@@ -98,9 +92,10 @@ print(JDKSObject.getObject())
|
|
98
92
|
```
|
99
93
|
---
|
100
94
|
|
101
|
-
### JSON_DUPLICATE_KEYS.get(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
95
|
+
### JSON_DUPLICATE_KEYS.get(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
102
96
|
_Get value in the JSON object by `name`_
|
103
97
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
98
|
+
- `case_insensitive`: the key name case (in)sensitive
|
104
99
|
- `separator`:
|
105
100
|
- `parse_index`:
|
106
101
|
- `_isDebug_`: Show/ Hide debug error messages
|
@@ -122,10 +117,11 @@ print(JDKSObject.get("snapshot||author"))
|
|
122
117
|
```
|
123
118
|
---
|
124
119
|
|
125
|
-
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
120
|
+
### JSON_DUPLICATE_KEYS.set(`name`, `value`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
126
121
|
_Set a new `name` and `value` for the JSON object_
|
127
122
|
- `name`: new key name for the JSON object. Supported flat key name format
|
128
123
|
- `value`: value for key `name`
|
124
|
+
- `case_insensitive`: the key name case (in)sensitive
|
129
125
|
- `separator`:
|
130
126
|
- `parse_index`:
|
131
127
|
- `dupSign_start`:
|
@@ -186,12 +182,17 @@ print(JDKSObject.getObject())
|
|
186
182
|
```
|
187
183
|
---
|
188
184
|
|
189
|
-
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
190
|
-
_Update new `value` for existing `name` in the JSON object_
|
185
|
+
### JSON_DUPLICATE_KEYS.update(`name`, `value`, `case_insensitive`=False, `allow_new_key`=False, `separator`="||", `parse_index`="$", `dupSign_start`="{{{", `dupSign_end`="}}}", `ordered_dict`=False, `_isDebug_`=False)
|
186
|
+
_Update new `value` for existing `name` or Set a new `name` in the JSON object_
|
191
187
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
192
188
|
- `value`: new value for key `name`
|
189
|
+
- `case_insensitive`: the key name case (in)sensitive
|
190
|
+
- `allow_new_key`: allows to create a new key name if the key name does not exist
|
193
191
|
- `separator`:
|
194
192
|
- `parse_index`:
|
193
|
+
- `dupSign_start`:
|
194
|
+
- `dupSign_end`:
|
195
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
195
196
|
- `_isDebug_`: Show/ Hide debug error messages
|
196
197
|
```python
|
197
198
|
import json_duplicate_keys as jdks
|
@@ -211,9 +212,10 @@ print(JDKSObject.getObject())
|
|
211
212
|
```
|
212
213
|
---
|
213
214
|
|
214
|
-
### JSON_DUPLICATE_KEYS.delete(`name`, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
215
|
+
### JSON_DUPLICATE_KEYS.delete(`name`, `case_insensitive`=False, `separator`="||", `parse_index`="$", `_isDebug_`=False)
|
215
216
|
_Delete a key-value pair in a JSON object by key `name`_
|
216
217
|
- `name`: the key name of the JSON object. Supported flatten key name format
|
218
|
+
- `case_insensitive`: the key name case (in)sensitive
|
217
219
|
- `separator`:
|
218
220
|
- `parse_index`:
|
219
221
|
- `_isDebug_`: Show/ Hide debug error messages
|
@@ -241,7 +243,7 @@ print(JDKSObject.getObject())
|
|
241
243
|
- `name`:
|
242
244
|
- `separator`:
|
243
245
|
- `parse_index`:
|
244
|
-
- `ordered_dict`:
|
246
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
245
247
|
```python
|
246
248
|
import json_duplicate_keys as jdks
|
247
249
|
|
@@ -262,7 +264,7 @@ print(JDKSObject.dumps())
|
|
262
264
|
- `value`:
|
263
265
|
- `separator`:
|
264
266
|
- `parse_index`:
|
265
|
-
- `ordered_dict`:
|
267
|
+
- `ordered_dict`: preserves the order in which the Keys are inserted
|
266
268
|
```python
|
267
269
|
import json_duplicate_keys as jdks
|
268
270
|
|
@@ -380,6 +382,12 @@ print(JDKSObject.getObject())
|
|
380
382
|
---
|
381
383
|
|
382
384
|
## CHANGELOG
|
385
|
+
#### [json-duplicate-keys v2024.11.28](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.28)
|
386
|
+
- **Fixed**: Add subkey name to empty dict of existing key name
|
387
|
+
|
388
|
+
#### [json-duplicate-keys v2024.11.19](https://github.com/truocphan/json-duplicate-keys/tree/2024.11.19)
|
389
|
+
- **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
|
390
|
+
|
383
391
|
#### [json-duplicate-keys v2024.7.17](https://github.com/truocphan/json-duplicate-keys/tree/2024.7.17)
|
384
392
|
- **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.
|
385
393
|
|