Back to Home
$jsonSetString
$jsonSetString sets or replaces a value at a specified key,
always storing it as a string. Use this instead of
$jsonSet when working with large numbers to avoid precision
loss.
Syntax
$jsonSetString[Key;...;Value]
-
Key: one or more keys forming the path to the target location. Value: the value to set, stored as a string.
What happens
$jsonParseloads the JSON object into memory.-
$jsonSetStringsets the value at the given key, wrapped in quotes so it is stored as a string type in the JSON. - Nothing is returned. Use
$jsonto read it back.
Example 1: Store a large number safely
$nomention
$jsonParse[{}]
$jsonSetString[balance;788895455566645444567]
Balance: $json[balance]
What happens:
$jsonParsecreates an empty object.-
$jsonSetStringstores the number as a string, preserving every digit. $json[balance]reads it back correctly.
Output:
Balance: 788895455566645444567
If $jsonSet were used instead, the number would lose
precision because JSON's native number type cannot handle integers
that large accurately.
Example 2: Store user input
$nomention
$jsonParse[{}]
$jsonSetString[coins;$message]
Coins set to: $json[coins]
What happens:
$jsonParsecreates an empty object.-
$jsonSetStringstores whatever the user typed as a string. $json[coins]reads it back.
If the user runs !example 500:
Coins set to: 500
Common uses
- Economy commands: always store coin balances and large numbers as strings to avoid precision issues
-
User input: store values from
$messagethat may be numeric but need to stay accurate