# SUGGESTION - JSON file to control settings of WS scripts

**URL:** https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623
**Category:** General Discussion
**Created:** [July 20, 2023, 9:34pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623 "2023-07-20T21:34:33Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 20, 2023, 9:34pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/1 "2023-07-20T21:34:34Z")

</div>

Hi again @florian, another request. This time a lot more involved.

In my latest version just below the `[ParserScriptAlbum]=...` there's a load of settings like below:

```auto
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# .:: U S E R O P T I O N S ::. #
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#

RegexpReplace "\(*Original Mix\)*" "" # Replace "" to your liking, block this with # to keep the original setting
RegexpReplace "(?i)\s+f(ea)?t\.*\s+" " feat. " # 'ft. => feat.' 'Ft. => feat.' 'Feat. => feat.'

# Leave only one of these lines below uncommented with no # preceding the line for each option (e.g. DATE & YEAR)

# DATE OPTIONS (Defaults to YYYY-MM-DD, so leave this commented out for this output)
# Set "OPTION:DATE_in_DDMM_format" "Add # at the start of this line to turn off this option"
# Set "OPTION:DATE_in_MMDD_format" "Add # at the start of this line to turn off this option"

# GENRE RENAME OPTION ('Progressive House' => 'House Progressive', 'Electro House' => 'House Electro', etc.)
Set "OPTION:GENRE_RENAME" "Add # at the start of this line to turn off this option"

# etc, etc...

```

And in the code, I do if statements to control these settings.

I wondered if this could be an external file that could be read and a dialog pop up to show this as settings.

The JSON file could look like so with the title of the dialog as:  
**Beatport Settings for stevehero WS Script v6** :

```auto
{
  "Beatport Settings for stevehero WS Script v6": [{
      "name": "DATE in DDMM format or MMDD format",
      "tooltip": "DATE in DDMM format or MMDD format.\n\nWill go here :)",
      "option": [{
          "variable": "OPTION:DATE_in_DDMM_format",
          "value": true
        },
        {
          "variable": "OPTION:DATE_in_MMDD_format",
          "value": false
        }
      ]
    },
    {
      "name": "Genre Rename (Progressive House => House Prog)",
      "tooltip": "Genre Rename (Progressive House => House Prog) tooltip.\n\nWill go here :)",
      "option": [{
        "variable": "OPTION:GENRE_RENAME",
        "value": true
      }]
    },
    {
      "name": "Add Padding to INITIALKEY",
      "tooltip": "Add Padding to INITIALKEY tooltip.\n\nWill go here :)",
      "option": [{
        "variable": "OPTION:INITIALKEY_ADD_PADDING",
        "value": true
      }]
    },
    {
      "name": "Add Padding to TOTALTRACKS",
      "tooltip": "Add Padding to TOTALTRACKS tooltip.\n\nWill go here :)",
      "option": [{
        "variable": "OPTION:TOTALTRACKS_ADD_PADDING",
        "value": true
      }]
    },
    {
      "name": "Add Padding to TRACK",
      "tooltip": "Add Padding to TRACK tooltip.\n\nWill go here :)",
      "option": [{
        "variable": "OPTION:TRACK_ADD_PADDING",
        "value": true
      }]
    },
    {
      "name": "Append TOTALTRACKS to TRACK",
      "tooltip": "Append TOTALTRACKS to TRACK tooltip.\n\nWill go here :)",
      "option": [{
        "variable": "OPTION:TRACK_TOTALTRACKS_APPEND",
        "value": true
      }]
    }
  ]
}

```

Then this JSON file will appear in the menu like so:

 ![image](https://community.mp3tag.de/uploads/default/original/2X/5/5461192de1c8e64928f4636b7c32aeebc29834c3.png)

Clicking on this would make a dialog appear that will read the JSON file and show a dialog with checkboxes or radio buttons for each of the JSON objects.

The way I see this is, if the `options` array is only one a checkbox appears, if more than one then radio buttons appear as you can only have one or the other.

I guess you could put in strings also.

Then in my scripts, I could call a New function named `GetVar` to call the `option` object to retrieve the boolean or string.

* * *

**The huge benefit is:**

- When users upgrade, these settings are kept intact
- One setting file can be used for multiple scripts without the need to find and replace code in multiple files
- Can be used for any future upgrades
- People not adept at coding can easily tweak the output very easily.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 1, 2023, 8:26pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/2 "2023-08-01T20:26:25Z")

</div>

I've thought about this over the past days and like it a lot. Thank you for the suggestion.

I've also thought about the data schema for the JSON settings and came up with a slightly different version than you've suggested. I've used your existing settings to create an initial example settings schema:

```json
{
  "settings": [
    {
      "type": "string",
      "key": "dateFormat",
      "title": "DATE Format",
      "description": "Format used for the DATE field.",
      "choices": [
        "YYYY-MM-DD",
        "MMDD",
        "DDMM"
      ],
      "default": "YYYY-MM-DD"
    },
    {
      "type": "string",
      "key": "yearFormat",
      "title": "YEAR Format",
      "description": "Format used for the YEAR field.",
      "choices": [
        "YYYY-MM-DD",
        "DD-MM-YYYY",
        "YYYY"
      ],
      "default": "YYYY-MM-DD"
    },
    {
      "type": "bool",
      "key": "genreRename",
      "title": "Rename Genres",
      "description": "'Progressive House' => 'House Progressive', 'Electro House' => 'House Electro', etc.",
      "default": true
    },
    {
      "type": "bool",
      "key": "initialkeyAddPadding",
      "title": "Add Padding to INITIALKEY",
      "description": "8A => 08A, 7B => 07B, etc.",
      "default": true
    },
    {
      "type": "bool",
      "key": "initialkeyAddPadding",
      "title": "Add Padding to INITIALKEY",
      "description": "8A => 08A, 7B => 07B, etc.",
      "default": true
    },
    {
      "type": "string",
      "key": "initialkeyFormat",
      "title": "INITIALKEY Format",
      "description": "Format used for the INITIALKEY field.",
      "choices": [
        "camelot",
        "musical"
      ],
      "default": "camelot"
    },
    {
      "type": "bool",
      "key": "totaltracksAddPadding",
      "title": "Add Padding to TOTALTRACKS",
      "default": true
    },
    {
      "type": "bool",
      "key": "trackAddPadding",
      "title": "Add Padding to TRACK",
      "default": true
    },
    {
      "type": "bool",
      "key": "trackTotaltracksAppend",
      "title": "Append TOTALTRACKS to TRACK",
      "description": "1/10, 2/10, 3/10 etc.",
      "default": true
    }
  ]
}

```

What I currently have in mind is that this information is stored in, e.g.,  
`Beatport by &stevehero v6#SETTINGS.settings`

which can be referenced in, e.g.,  
`Beatport by &stevehero v6_Release Search.inc`

via a new key  
`[Settings]=Beatport by &stevehero v6#SETTINGS.settings`

to make the settings available to the WS.

The actual values that are configured by the user should most likely be stored in a separate file, e.g.,  
`Beatport by &stevehero v6#SETTINGS.user` as simple key-value pairs, e.g.,

```json
{
  "dateFormat": "MMDD",
  "genreRename": false
}

```

This ensures that you can add new configuration options with future versions of the WS without the need to ask users to copy the additions to their settings file. It would just use the default if there is no value for the added key in the `.user` file.

* * *

I've also thought about how to access the settings and think a dedicated function  
`IfVar "key" "value"`

would be best. With the examples above, you'd use

```plaintext
IfVar "dateFormat" "MMDD"
  ...
Else
 ...
Endif

```

or

```plaintext
IfVar "genreRename" "true"
  ...
Else
 ...
Endif

```

* * *

I still need to implement all that, maybe without the dynamic generation of the UI in the first iteration. But I wanted to share this, so that you and others can potentially comment on my initial ideas.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 2, 2023, 12:01am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/3 "2023-08-02T00:01:45Z")

</div>

Thanks, Florian, I was worried this may be too much work for you but I feel it's something that can be expanded on as you say and will hopefully not scare people from using scripts because they can't set them up like they would like.

* * *

My only suggestion is to have the JSON file set up so the UI idea can be added without the need for people to swap it out with a newer one.

**Things like the:**

- The Title of the dialog
- Tooltips (maybe that's what description is?)

**One Question for now:**

- Would multiple radio buttons be possible? e.g. more than 2.

* * *

> [@Florian](#):
>
> This ensures that you can add new configuration options with future versions of the WS without the need to ask users to copy the additions to their settings file. It would just use the default if there is no value for the added key in the `.user` file.

Perfect 🙂

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 2, 2023, 5:58am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/4 "2023-08-02T05:58:43Z")

</div>

> [@stevehero](#):
>
> My only suggestion is to have the JSON file set up so the UI idea can be added

Yes, I plan to add UI-only types like `title` for the title of the dialog. I've used `description` for the description of the individual configuration setting to allow it to be used in other contexts than a tooltip.

> [@stevehero](#):
>
> Would multiple radio buttons be possible? e.g. more than 2.

I thought about using a drop-down list for those settings, as in `dateFormat` above, where the user then can select the desired format from the list.

---

<div class="post-metadata">

### Author: ![AreDigg](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@AreDigg](https://community.mp3tag.de/u/AreDigg)
#### Post date: [August 2, 2023, 10:19am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/5 "2023-08-02T10:19:02Z")

</div>

This is a great idea and would help with making the scripts more versatile and relevant for more people without needing too many variants and that users need to modify them.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 2, 2023, 10:55am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/6 "2023-08-02T10:55:39Z")

</div>

Drop downs work for me too. This will be a huge feature to add so thanks for even considering it Florian 👍🏻

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 3, 2023, 7:13pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/7 "2023-08-03T19:13:28Z")

</div>

I've worked quite extensively on this over the past days and refined my original design further. Here is the current status.

This is the definition of a settings schema for a Beatport Tag Source and needs to be stored in a `*.settings` file, e.g.,  
`Beatport by &stevehero v6#SETTINGS.settings`

and will be referenced in, e.g.,  
`Beatport by &stevehero v6_Release Search.inc`

via a new key  
`[Settings]=Beatport by &stevehero v6#SETTINGS.settings`

to make the settings available to the WS.

```json
{
  "key": "beatport",
  "title": "Beatport Settings",
  "settings": [
    {
      "type": "string",
      "key": "dateFormat",
      "title": "DATE Format",
      "description": "Format used for the DATE field.",
      "choices": [
        "YYYY-MM-DD",
        "MMDD",
        "DDMM"
      ],
      "default": "YYYY-MM-DD"
    },
    {
      "type": "string",
      "key": "yearFormat",
      "title": "YEAR Format",
      "description": "Format used for the YEAR field.",
      "choices": [
        "YYYY-MM-DD",
        "DD-MM-YYYY",
        "YYYY"
      ],
      "default": "YYYY-MM-DD"
    },
    {
      "type": "bool",
      "key": "genreRename",
      "title": "Rename Genres",
      "description": "'Progressive House' => 'House Progressive', 'Electro House' => 'House Electro', etc.",
      "default": true
    },
    {
      "type": "bool",
      "key": "initialkeyAddPadding",
      "title": "Add Padding to INITIALKEY",
      "description": "8A => 08A, 7B => 07B, etc.",
      "default": true
    },
    {
      "type": "string",
      "key": "initialkeyFormat",
      "title": "INITIALKEY Format",
      "description": "Format used for the INITIALKEY field.",
      "choices": [
        "camelot",
        "musical"
      ],
      "default": "camelot"
    },
    {
      "type": "bool",
      "key": "totaltracksAddPadding",
      "title": "Add Padding to TOTALTRACKS",
      "default": true
    },
    {
      "type": "bool",
      "key": "trackAddPadding",
      "title": "Add Padding to TRACK",
      "default": true
    },
    {
      "type": "bool",
      "key": "trackTotaltracksAppend",
      "title": "Append TOTALTRACKS to TRACK",
      "description": "1/10, 2/10, 3/10 etc.",
      "default": true
    }
  ]
}

```

To configure the settings, the user would use the dedicated menu item that is created at the end of the Tag Sources menu, separated from the actual Tag Sources. The example name `Beatport by &stevehero v6#SETTINGS.settings` results in a menu item `SETTINGS` in the `Beatport by &stevehero v6` submenu.

Choosing this menu item shows a dedicated dialog that is generated based on the individual settings schema.

The actual values that are configured by the user are stored in a separate file `settings.json` as simple key-value pairs, e.g.,

```json
{
  "beatport": {
    "dateFormat": "MMDD",
    "genreRename": false
    "yearFormat": "YYYY"
  }
}

```

Note, that this settings file is used for the user settings of all Tag Sources. The individual objects use the `key` from the respective settings schema definition.

This ensures that you can add new configuration options with future versions of the WS without the need to ask users to copy the additions to their settings file. It would just use the default if there is no value for the added key in the `settings.json` file.

* * *

A dedicated function is used to access the individual settings in the WS, where the `key` is used to access the setting which is compared to the given `value`.

`IfVar "key" "value"`  
`IfNotVar "key" "value"`

With the examples above, you'd use

```plaintext
IfVar "genreRename" "true"
  ...
Else
 ...
Endif

```

or

```plaintext
IfNotVar "dateFormat" "MMDD"
  ...
Else
 ...
Endif

```

---

<div class="post-metadata">

### Author: ![AreDigg](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@AreDigg](https://community.mp3tag.de/u/AreDigg)
#### Post date: [August 4, 2023, 5:10am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/8 "2023-08-04T05:10:28Z")

</div>

In addition it should be possible to localize the text strings.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 7, 2023, 9:28pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/9 "2023-08-07T21:28:44Z")

</div>

Also, an edit box to allow a user to type a string would be great.

I want to get allow users to change the way feat. is done as some like it like:  
`ft.`  
`feat.` or  
`featuring`.

So I think a `GetVar` function would be great too.

But not sure how difficult this would be to implement because you'd have to do something like this:

```auto
RegexpReplace "(?i)\s+f(ea)?t\.*\s+" GetVar "SettingFeaturingString" # 'ft. => feat.' 'Ft. => feat.' 'Feat. => feat.'

```

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 7, 2023, 9:57pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/10 "2023-08-07T21:57:29Z")

</div>

This is beyond the scope for now, you'd need to provide some sensible defaults for the user to choose from and handle the variations in the script.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 7, 2023, 10:32pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/11 "2023-08-07T22:32:58Z")

</div>

Ok, I guess that could work too but less customisable.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 7, 2023, 11:32pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/12 "2023-08-07T23:32:42Z")

</div>

A restore defaults button somewhere?

And perhaps a method for a separator?

As you see there will be a lot of settings. **EDIT** : This may cause an issue with small monitors so a scrollbar may be needed.

 ![image](https://community.mp3tag.de/uploads/default/original/2X/e/eb83c30f729d0d2a8fc236a0a3011ba75e8edfe3.png)

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 8, 2023, 6:52am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/13 "2023-08-08T06:52:06Z")

</div>

I think all the remove fields settings should better be handled via the field checkboxes I’ve added to the adjust tag information dialog a while ago.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [August 8, 2023, 8:21am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/14 "2023-08-08T08:21:56Z")

</div>

It doesn't stop people from editing the scripts and breaking them. Please see the latest few replies on the Beatport thread. So this is why I will be adding these global options.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 14, 2023, 10:00pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/15 "2023-08-14T22:00:13Z")

</div>

In addition to what I've described [above in #7](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/7), I've worked on dynamic adaptation of the dialog height to a size that shows the most options. I've also added a separator type that simple shows a line between controls and has an optional title:

```auto
{
  "type": "separator"
  "title": "Optional Separator Text"
}

```

If you're looking for a visually more distinctive header text, I've also added a heading type that creates a bold text control with different background:

```auto
{
  "type": "heading"
  "title": "Header Text"
}

```

This is now available with [Mp3tag v3.21h](https://community.mp3tag.de/t/455).

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 15, 2023, 5:50pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/16 "2023-08-15T17:50:55Z")

</div>

This is now also available on macOS with [Mp3tag for Mac v1.8.2](https://community.mp3tag.de/t/mp3tag-for-mac-v1-8-released/61431/5).

---

<div class="post-metadata">

### Author: ![AreDigg](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@AreDigg](https://community.mp3tag.de/u/AreDigg)
#### Post date: [August 16, 2023, 4:10pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/17 "2023-08-16T16:10:37Z")

</div>

This seem great, and seem to work fine in the script, except (at least on Mac) it does not actually save the settings to the settings.json file (or remember the settings). I had to manually create settings.json file as well, otherwise it would just complain about the file not existing.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 16, 2023, 5:00pm UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/18 "2023-08-16T17:00:04Z")

</div>

Thanks for pointing! It's getting created automatically on Windows and I'll fix that for macOS with the next release. I'll keep you posted.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 17, 2023, 9:07am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/19 "2023-08-17T09:07:10Z")

</div>

> [@AreDigg](#):
>
> except (at least on Mac) it does not actually save the settings to the settings.json file (or remember the settings)

I've just released [Mp3tag for Mac v1.8.3](https://community.mp3tag.de/t/mp3tag-for-mac-v1-8-released/61431/6) which should fix this issue. Thanks again for reporting — and for experimenting with the new features!

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [August 17, 2023, 9:08am UTC](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623/20 "2023-08-17T09:08:41Z")

</div>

I'll think about a solution that doesn't require replicating the configuration schema for each language and keeps everything in one place.

[Next page](https://community.mp3tag.de/t/suggestion-json-file-to-control-settings-of-ws-scripts/61623.md?page=2)
