[WS] JSON_NORMALIZE. Manipulate JSON utility

I have managed to create a "utility" JSON_NORMALIZE.inc which can help WS authors manipulate JSON input stream (missing information, move info)

Features:

  1. 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

  2. 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

  3. 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

  4. Add elements _OBJECT_BEGIN_, _OBJECT_END_ as first/last elements of an object ({})

  5. Add elements _ARRAY_BEGIN_, _ARRAY_END_ as first/last elements of each object within array ({} within [])

  6. Add array ascending index to value of _ARRAY_BEGIN_

  7. Add element _ARRAY_LAST_ELEMENT_ (value "yes") at the last object of an array

Real Usages:

  1. Certain JSON do not have Track numbers
  2. Move Discogs credits into tracklist part (still working on it)
  3. 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.

The involved people stopped working, in the example and any other album i press the album in the index it gives an error, or:

@Romano please use the VGMdb script.
I had initially uploaded a wrong version. It was updated 1h ago.
I will download the uploaded script and test (just in case).
The script is only one example (one fixed album from your VTGdb thread).
Update: Your initial album link works well now. Indeed it was an issue with Involved people.
Each JSON key includes the full path. This is fully customizable when executing JSON Normalizer.

1 Like

Thank you, i need time to absorve all of this. i am a newbie still.

v2.01 JSON_NORMALIZE_v2.01.zip (4.0 KB)