Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.SetVariables
Creates local variables in script for JSON.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 15.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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 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"; $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: "<a><test>Hello¶World\¶\t" & Char(34) & "!</test></a>" ]
Set Variable [ $json ; Value: JSONSetElement ( "{}" ; "abc" ; "Hello¶World\¶\a" & Char(34) & "!" ; JSONString ) ]
#
# set variables
Set Variable [ $r ; Value: MBS("XML.SetVariables"; $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
Release notes
- Version 15.0
- Added JSON.SetVariables and JSON.ClearVariables.
- Improved JSON.SetVariables and XML.SetVariables functions to work better with multi line texts.
Example Databases
Blog Entries
Created 25th November 2024, last changed 27th December 2024