JSON parsing script
This commit is contained in:
parent
2c7af4bd40
commit
9b3273c4a7
3 changed files with 41 additions and 0 deletions
3
acpi/anything
Normal file
3
acpi/anything
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Pass all events to our one handler script
|
||||
event=.*
|
||||
action=/etc/acpi/handler.sh %e
|
||||
37
json_fields.py
Executable file
37
json_fields.py
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
import json
|
||||
|
||||
fields = {}
|
||||
|
||||
def fielding(jsons, out, field = None):
|
||||
for key, value in jsons.items():
|
||||
if field is None:
|
||||
if key not in out:
|
||||
out[key] = set()
|
||||
if isinstance(value, dict):
|
||||
fielding(value, out, nulls = nulls, field = key)
|
||||
elif isinstance(value, list):
|
||||
for i in value:
|
||||
if isinstance(i, dict):
|
||||
fielding(i, out, nulls = nulls, field = key)
|
||||
else:
|
||||
out[key].add(value)
|
||||
else:
|
||||
out[field].add(key)
|
||||
if isinstance(value, dict):
|
||||
if key not in out:
|
||||
out[key] = set()
|
||||
fielding(value, out, nulls = nulls, field = key)
|
||||
elif isinstance(value, list):
|
||||
out[key] = set()
|
||||
for i in value:
|
||||
if isinstance(i, dict):
|
||||
fielding(i, out, nulls = nulls, field = key)
|
||||
return out, nulls
|
||||
|
||||
|
||||
|
||||
with open(r"/home/swebb/Downloads/musicbrainz.org.json", encoding='utf-8') as file:
|
||||
data = json.load(file)
|
||||
testout = fielding(data, fields)
|
||||
print(nulled)
|
||||
1
json_fields_out.json
Normal file
1
json_fields_out.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'created': '2025-03-08T05:16:38.312Z', 'count': 16, 'offset': 0, 'recordings': ['video', 'artist-credit', 'tags', 'isrcs', 'disambiguation', 'first-release-date', 'releases', 'id', 'title', 'score', 'length'], 'artist-credit': ['artist', 'name'], 'artist': ['sort-name', 'disambiguation', 'aliases', 'name', 'id'], 'aliases': ['sort-name', 'type-id', 'type', 'locale', 'end-date', 'name', 'begin-date', 'primary'], 'releases': ['artist-credit', 'media', 'status-id', 'status', 'disambiguation', 'release-group', 'date', 'country', 'release-events', 'count', 'id', 'title', 'track-count'], 'release-group': ['type-id', 'primary-type-id', 'secondary-type-ids', 'secondary-types', 'primary-type', 'id', 'title'], 'release-events': ['area', 'date'], 'area': ['id', 'sort-name', 'iso-3166-1-codes', 'name'], 'iso-3166-1-codes': null, 'media': ['track-offset', 'format', 'position', 'track', 'track-count'], 'track': ['id', 'title', 'length', 'number'], 'secondary-types': null, 'secondary-type-ids': null, 'isrcs': null, 'tags': ['name', 'count']}
|
||||
Loading…
Add table
Add a link
Reference in a new issue