Sign In

JSON Functions

Nicky
by Nicky•Updated Oct 17, 2026

In this guide, you will learn how to use various JSON functions in ForgeScript. Let's get started!

Note

Before reading this guide, you should be familiar with what JSON is and where and how it is being used. You can familiarize yourself with JSON by reading tutorials on W3Schools.

Table of Contents

  1. $jsonLoad[]
  2. $jsonSet[]
  3. $jsonDelete[]
  4. $jsonAssign[]
  5. $jsonHas[]
  6. $jsonKeys[]
  7. $jsonValues[]
  8. $jsonEntries[]
  9. $jsonStringify[]

1. $jsonLoad[]

This function loads the specified JSON object to an environment variable.

Syntax

$jsonLoad[variable;json]

Fields

  • variable - The variable name to load the JSON object to.
  • json - The JSON object to load to the variable.

Example

$jsonLoad[data;{
    "user": {
        "id": "729343563401265193",
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him"
        \\]
    }
}]

Username: $env[data;user;username]
Pronouns: $env[data;user;pronouns;0]
Tip

We use $env[...key?] to retrieve the JSON value of an environment variable. This function is also called $jsonDump[].

Output

Username: itsnicky.
Pronouns: He/Him

2. $jsonSet[]

This function adds a JSON key with a new value to a JSON object.

Note

This function returns a boolean depending on whether the JSON key was added successfully. To disable this output, use the negation operator.

Syntax

$jsonSet[...keys?;value]

Fields

  • ...keys? - The JSON key where the new value will be set. This field can be repeated.
  • value - The new value to set at the specified JSON key.

Example

$jsonLoad[data;{
    "user": {
        "id": "729343563401265193",
        "username": "itsnicky.",
        "displayName": "ncy",
        "pronouns": [
            "He/Him"
        \\]
    }
}]
$!jsonSet[data;user;displayName;Nicky]
$!jsonSet[data;user;banner;{}]
$!jsonSet[data;user;banner;color;$userAccentColor]

$env[data]

Output

{
    "user": {
        "id": "729343563401265193",
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him"
        ],
        "banner": {
            "color": "#41333c"
        }
    }
}

3. $jsonDelete[]

This function deletes a JSON key from a JSON object.

Note

This function returns a boolean depending on whether the JSON key was deleted successfully. To disable this output, use the negation operator.

Syntax

$jsonDelete[...keys?]

Fields

  • ...keys? - The JSON key to delete. This field can be repeated.

Example

$jsonLoad[data;{
    "user": {
        "id": "729343563401265193",
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him"
        \\],
        "banner": {
            "color": "#41333c"
        }
    }
}]
$!jsonDelete[data;user;id]
$!jsonDelete[data;user;pronouns;0]

$env[data]

Output

{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [],
        "banner": {
            "color": "#41333c"
        }
    }
}

4. $jsonAssign[]

This function combines multiple JSON objects into a single JSON object.

Syntax

$jsonAssign[variable;other variable?;...objects?]

Fields

  • variable - The variable name that holds the target object.
  • other variable? - The variable to load the result to, leave empty to return output.
  • ...objects? - The objects from which to copy properties. This field can be repeated.

Example

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [\\],
        "banner": {
            "color": "#41333c"
        }
    }
}]
$jsonLoad[user;$env[data;user]]

$jsonAssign[user;;{ "id": "729343563401265193" };{ "isBot": false }]

Output

{
    "username": "itsnicky.",
    "displayName": "Nicky",
    "pronouns": [],
    "banner": {
        "color": "#41333c"
    },
    "id": "729343563401265193",
    "isBot": false
}

5. $jsonHas[]

This function returns whether a key exists in a JSON object.

Syntax

$jsonHas[variable;key]

Fields

  • variable - The variable name to get JSON object from.
  • key - The key to check for in the JSON object.

Example

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [\\],
        "banner": {
            "color": "#41333c"
        }
    }
}]
$jsonLoad[user;$env[data;user]]

$jsonHas[user;id]
$jsonHas[user;banner]

Output

In this example, the key "id" does not exist, resulting in false. The key "banner" does exist, resulting in true.

false
true

6. $jsonKeys[]

This function returns all JSON keys from a JSON object.

Syntax

$jsonKeys[variable]

Fields

  • variable - The variable name to get JSON keys from.

Example

In this example, we get all JSON keys of the user object.

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him",
            "They/Them"
        \\],
        "isBot": false
    }
}]
$jsonLoad[user;$env[data;user]]

$jsonKeys[user]

Output

[
    "username",
    "displayName",
    "pronouns",
    "isBot"
]

7. $jsonValues[]

This function returns all JSON values from a JSON object.

Syntax

$jsonValues[variable;separator?]

Fields

  • variable - The variable name to get JSON values from.
  • separator? - The optional separator to use for each value.

Example

In this example, we get all JSON values of the user object separated by a new line.

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him",
            "They/Them"
        \\],
        "isBot": false
    }
}]
$jsonLoad[user;$env[data;user]]

$jsonValues[user;
]

Output

itsnicky.
Nicky
He/Him,They/Them
false

8. $jsonEntries[]

This function returns all JSON entries from a JSON object.

Syntax

$jsonEntries[variable]

Fields

  • variable - The variable name to get JSON entries from.

Example

In this example, we get all JSON entries of the user object.

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him",
            "They/Them"
        \\],
        "isBot": false
    }
}]
$jsonLoad[user;$env[data;user]]

$jsonEntries[user]

Output

[
    [
        "username",
        "itsnicky."
    ],
    [
        "displayName",
        "Nicky"
    ],
    [
        "pronouns",
        [
            "He/Him",
            "They/Them"
        ]
    ],
    [
        "isBot",
        false
    ]
]

9. $jsonStringify[]

This function returns the JSON in stringified format.

Syntax

$jsonStringify[variable;space?]

Fields

  • variable - The variable name that holds the JSON to stringify.
  • space? - The number of spaces to use for stringifying JSON.

Example

In this example, we stringify the JSON with and without spaces.

$jsonLoad[data;{
    "user": {
        "username": "itsnicky.",
        "displayName": "Nicky",
        "pronouns": [
            "He/Him",
            "They/Them"
        \\],
        "isBot": false
    }
}]

2 Spaces:
$jsonStringify[data;2]

No Spaces:
$jsonStringify[data]

Output

2 Spaces:
{
  "user": {
    "username": "itsnicky.",
    "displayName": "Nicky",
    "pronouns": [
      "He/Him",
      "They/Them"
    ],
    "isBot": false
  }
}

No Spaces:
{"user":{"username":"itsnicky.","displayName":"Nicky","pronouns":["He/Him","They/Them"],"isBot":false}}

Was this page helpful?