I have managed to create a "utility" JSON_NORMALIZE.inc which can help WS authors manipulate JSON input stream (missing information, move info)
Features:
-
Wrap all keys between «» e.g. "«Companies»".
Can be activated by populating temporary tag "JSON_NORMALIZE_KEY_WRAP"
outputto "JSON_NORMALIZE_KEY_WRAP"
say "yes" # any non blank value would work the same -
Add all parent keys to each JSON key "Key1-Key2-Key3"
Can be activated by populating temporary tag "JSON_NORMALIZE_KEY_PATH"
outputto "JSON_NORMALIZE_KEY_PATH"
say "yes" # any non blank value would work the same -
Wrap values between ‟” inside double quotes, e.g. "‟Album”"
This option is useful when searching/scanning certain values/value patterns.
Careful when using this feature.
if "" and ifnot "" might not bring desired results. Remove boundaries first before if condition.
Can be activated by populating temporary tag "JSON_NORMALIZE_VALUE_WRAP"
outputto "JSON_NORMALIZE_VALUE_WRAP"
say "yes" # any non blank value would work the same -
Add elements _OBJECT_BEGIN_, _OBJECT_END_ as first/last elements of an object ({})
-
Add elements _ARRAY_BEGIN_, _ARRAY_END_ as first/last elements of each object within array ({} within [])
-
Add array ascending index to value of _ARRAY_BEGIN_
-
Add element _ARRAY_LAST_ELEMENT_ (value "yes") at the last object of an array
Real Usages:
- Certain JSON do not have Track numbers
- Move Discogs credits into tracklist part (still working on it)
- Full path key and/or key boundaries might help some people.
e.g.
json_foreach "«tracklist»" ifnot "0" json_foreach "«tracklist-extraartists»" ifnot "0" outputto "credits" json_select "«tracklist-extraartists-name»" sayrest say ", " endif endif json_foreach_end
or (without path)
json_foreach "«tracklist»" ifnot "0" json_foreach "«extraartists»" ifnot "0" outputto "credits" json_select "«name»" sayrest say ", " endif endif json_foreach_end
Download JSON_NORMALIZE.inc here JSON_NORMALIZE.zip (3.8 KB)
A working example for VGMdb (calculate missing Tracks, Tracktotal, Disc number and TotalDiscs) VGMdb#Search by &Album JSON Normalize.src (20.8 KB)
Update: If input Json is multiline a JoinLine NNNN command must be executed first.
Any attempt with an arbitrary large number of lines (10000) fails the script. It has been addressed to Florian. Hopefully we will have some good news.
Discogs returns single line Json.