Parse JSON Utility

Example code for parsing arbitrary JSON data into Streamer.bot variables

Whipstickgostop

Sometimes you may want to parse JSON data from an API response or other source into Streamer.bot variables for use in your actions. This utility action provides a simple way to do that using C# code.

This utility action will take a JSON string as input, parse it, and store the resulting data in Streamer.bot variables that you can use in subsequent actions.

  1. Copy the import code above
  2. Click Import at the top of Streamer.bot to open the Import Dialog
  3. Paste the import code into the Import String field in Streamer.bot

You should see the Name field populated with wsgs.utils.json.parse with a single action.

Click Import to add the wsgs.utils.json.parse action to your Streamer.bot instance.

All selected actions will be added to your Streamer.bot installation!
  • Create a new action, or open an existing action where you would like to parse JSON data.
  • Populate an argument named json with the JSON string you wish to parse. This can be from a previous action, API response, or any other source.
  • The Set Argument sub-action may be useful for this.
  • Add the Execute C# Method sub-action to your action. Ensure it is after you have set the json argument.
  • Select the wsgs.utils.json.parse code, and the Execute method.
  • Click OK to confirm.

After running the Parse JSON utility, the parsed data will be available in Streamer.bot variables.

For example, if your JSON data looks like this...

{
  "user": {
    "name": "StreamerBot",
    "age": 5,
    "isActive": true
  },
  "stats": {
    "followers": 1000,
    "views": 50000
  },
  "status": "ok"
}

You can then access the data using the following variable names in any subsequent sub-actions:

JSON PathVariable Name
user.name%json.user.name%
user.age%json.user.age%
user.isActive%json.user.isActive%
stats.followers%json.stats.followers%
stats.views%json.stats.views%
status%json.status%