# \[WS\] JSON\_NORMALIZE. Manipulate JSON utility

**URL:** https://community.mp3tag.de/t/ws-json-normalize-manipulate-json-utility/51062
**Category:** Web Sources Discussion
**Created:** [December 7, 2020, 10:24am UTC](https://community.mp3tag.de/t/ws-json-normalize-manipulate-json-utility/51062 "2020-12-07T10:24:17Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 7, 2020, 10:24am UTC](https://community.mp3tag.de/t/ws-json-normalize-manipulate-json-utility/51062/1 "2020-12-07T10:24:17Z")

</div>

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](https://community.mp3tag.de/uploads/short-url/yXW4tScm8XOeX9gNAb67yJoUlJA.zip) (3.8 KB)  
A working example for VGMdb (calculate missing Tracks, Tracktotal, Disc number and TotalDiscs) [VGMdb#Search by &Album JSON Normalize.src](https://community.mp3tag.de/uploads/short-url/jX308nkuPFIi4oDM64ALzMThDQ0.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.

---

_[View the full topic](https://community.mp3tag.de/t/ws-json-normalize-manipulate-json-utility/51062)._
