JSON.SetVariables
-----------------

Creates local variables in script for JSON.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JSON](component_JSON.md) | [15.0](newinversion150.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JSON.SetVariables"; JSON; Prefix ) 

**MBS**( **"JSON.SetVariables";** /\* Creates local variables in script for JSON. \*/  
**$JSON**; /\* A JSON text or reference.  
Must be an object. \*/   
**$Prefix**) /\* The prefix to use for the variables names.e.g. "" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| JSON | A JSON text or reference.   Must be an object. |  |
| Prefix | The prefix to use for the variables names. | "" |

### Result

Returns OK or error.

### Description

Creates local variables in script for JSON.  
Returns list of variable names.  
If variables receive multiple values the name in the result comes the highest index in square brackets.  
  
Recognizes numbers and passes them through as numbers. Arrays and objects in JSON are passed as JSON. Null values make empty variables and boolean values are passed as 1 for true and 0 for false.  
  
You can call [JSON.ClearVariables](JSONClearVariables.md) later to clear those variables, but at the end of the script all variables will go away. Variable names are shortened to a maximum of 100 characters.  
### Examples

Set some variables using JSON:

 Set Variable \[ $Variables ; Value: MBS ("JSON.SetVariables"; Table::JSON Insert) \]  
\# @variable $FirstName , $LastName , $Birthday   
Show Custom Dialog \[ "Names" ; $FirstName \]  
Set Variable \[ $r ; Value: MBS ("[JSON.ClearVariables](JSONClearVariables.md)"; $Variables ) \]  
Test variables in JSON and XML:

 # our test text with some variable values containing backslash, quote and a new line   
Set Variable \[ $xml ; Value: "&lt;a&gt;&lt;test&gt;Hello¶World\\¶\\t" &amp; Char(34) &amp; "!&lt;/test&gt;&lt;/a&gt;" \]  
Set Variable \[ $json ; Value: JSONSetElement ( "{}" ; "abc" ; "Hello¶World\\¶\\a" &amp; Char(34) &amp; "!" ; JSONString ) \]  
\#   
\# set variables   
Set Variable \[ $r ; Value: MBS ("[XML.SetVariables](XMLSetVariables.md)"; $xml ) \]  
Set Variable \[ $r ; Value: MBS ("JSON.SetVariables"; $json ) \]  
\# declare for our variable check   
\# @param $test , $abc   
\#   
\# and display   
Show Custom Dialog \[ "XML" ; $test \]  
Show Custom Dialog \[ "JSON" ; $abc \]  
### See also

- [JSON.ClearVariables](JSONClearVariables.md)
- [JSON.Release](JSONRelease.md)
- [XML.SetVariables](XMLSetVariables.md)

### Release notes

- **Version 15.0**
    - Added [JSON.SetVariables](https://www.mbsplugins.eu/JSONSetVariables.shtml) and [JSON.ClearVariables](https://www.mbsplugins.eu/JSONClearVariables.shtml).
    - Improved [JSON.SetVariables](https://www.mbsplugins.eu/JSONSetVariables.shtml) and [XML.SetVariables](https://www.mbsplugins.eu/XMLSetVariables.shtml) functions to work better with multi line texts.

### Example Databases

- [JSON/JSON Insert and Update](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Insert%20and%20Update.shtml#8ScriptAnchor_)

### Blog Entries

- [New in MBS FileMaker Plugin 15.0](https://www.mbsplugins.de/archive/2025-01-21/New_in_MBS_FileMaker_Plugin_15/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 15.0 für Claris FileMaker](https://www.mbsplugins.de/archive/2025-01-14/Neues_MBS_Plugin_150_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 15.0 for Claris FileMaker](https://www.mbsplugins.de/archive/2025-01-14/MBS_Plugin_150_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.0pr7](https://www.mbsplugins.de/archive/2025-01-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.6pr1](https://www.mbsplugins.de/archive/2024-12-02/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

Created 25th November 2024 , last changed 27th December 2024

  
[JSON.SetPathItem](JSONSetPathItem.md) - [JSON.Sort](JSONSort.md)

[HTML Version](JSONSetVariables.shtml)