Examples

Parse JSON Utility

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

Overview

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.

Setup

1

Load the import code

  • Click Import at the top of Streamer.bot to open the Import Dialog
  • Paste the following code into the Import String field:
Import Code
U0JBRR+LCAAAAAAABAC1V21zokgQ/n5V9x+sfD5TgJLIfQtEEfRMEAXl3A/DzAQIw8vyopKt/e83A2I00a29rTuqEJnunu5+np4Z+tvvv3U6NxEuwM2fnW/shb7GIML09ebvZRGQoAhw/qXzDLIcd3TzaXbzx0ENlIWfZEzR9oM0LwIYekleJOlRY4uzPEhipsLfcrfcUYBwDrMgLQ7CR4xTUnV2gISdws+S0vM7oHbWyYssiL3OS5ZEnS3IAuAS3NncvOZJvLnpgBh10iQtCSgwtchx0UleOiDzygjHRX4aajIv4wd48BiXhLSyKIiDqIysY6xMyGTfa40bBM7AAfUcOR35uxnptKJaHCCWkCBwLi+CfhdKEur2X6RBd9Dn77r3wuD+juPRgB/ANrja7GuJyxpz7nB1L/y015kljhkkzGuRlfhMsoekRHhEoRsHlJesokovgOTXtJ5xjCjYl7R+riRqVY/ylzLdo+qZGJAdqHJKxiU3GSU0iY40fZLDJIZlllFuL0lpqXgepZFx8+VUkJfuw2faPlD3L/P8QR2ntcF/WcDvAOEXTNOH+FMmtVj5c7OxA4rhLt9s/gpgluTJS3E7Gy42m1FGc9slWXjX32y2fboee1yPlzabKIdJRgL3FhHy0eGvzmlWeYGjKzPebjYzvCsoHWwinSJRK57rffmYulsVWElQTQ9azVI3gt6yR96QahVPO27ycWwazrauuifr3jx1BfFtGiLiRlYF7L/uH42UhwIpnUp+claIY3JXcLhpmNJnv1yopISLfKZ43ASOrcBVyaumzvL1avamDWeGOSQlHSsdg5tg6ltZyfw62qfrSg5cQcq1odV37BmP1GUyMZiczRXqwF57E2X0uBx6pTX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TV4Tto99ipW/xKD4xpgdqn06dsxzTBMojQg+MLH8+FzloDKLEB26fO6+ZIGWzzHeUmKRWIdvmZ/pHumddJ1HZWafqkHgYR6Eu5COHjp9hEGXfdevO/yIj2dB0gYYJf7lM8OB57PIqWd5UdZUaXMo8SuTzgA1kBo6EpEVxuqJt4Y4T3zeTr+/f3ly3m7QghIc4xU1hM1fUkrPti0+k0HeNa6UPMoog3C+eAOu3kCQ1yYONt+aHbehQoJ6v7hVFgEUat/0t6+9+hCrxnB+zTJCoxYS9i27nyD/udmuWnsu4CkPqBav//2/R8RrIl+UxAAAA==
You should then see the Name field populated with [Utilities] Parse JSON with a single action.
2

Confirm the Import

Click Import to add the Parse JSON Utility to your Streamer.bot instance.
3

Done!

All selected actions will be added to your Streamer.bot installation!

Usage

1

Prepare your action

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

Run the Parse JSON utility

  • Add the Execute C# Method sub-action to your action. Ensure it is after you have set the json argument.
  • Select the [Utilities] Parse JSON code, and the Execute method.
  • Click OK to confirm.
3

Access the parsed data

  • 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 access the data using the following variable names:
    • %json.user.name%
    • %json.user.age%
    • %json.user.isActive%
    • %json.stats.followers%
    • %json.stats.views%
    • %json.status%