Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Adds a new entry to the object with the given name and value.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 2.7 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
json | A JSON text or reference. | {"key":"value"} |
Name... | The name of the Object property. | "length" |
json2... | The JSON text for the item. | 50 |
Returns JSON code.
Build nested objects:
Set Variable [$j1; MBS( "JSON.CreateObject") ]
Set Variable [$j2; MBS( "JSON.AddStringToObject"; $j1; "name"; "" ) ]
Set Variable [$j3; MBS( "JSON.AddStringToObject"; $j2; "record_type"; "MX" ) ]
Display Dialog ["JSON"; $j3]
Set Variable [$j4; MBS( "JSON.CreateObject") ]
Set Variable [$j5; MBS( "JSON.AddItemToObject"; $j4; "record"; $j3 ) ]
Display Dialog ["JSON"; $j4]
Add two items to an object:
MBS( "JSON.AddItemToObject"; "{}"; "Values"; "[1,2]"; "Name"; "{\"FirstName\":\"Heinz\"}" )
Example result:
{
"Values": [1, 2],
"Name": {
"FirstName": "Heinz"
}
}
Add big number:
MBS( "JSON.AddItemToObject"; "{}"; "test"; "12063660878882855000013426248015578834577" )
Example result:
{
"test": 12063660878882855000013426248015578834577
}
Create JSON with values in fields on current layout:
Let ( [
// Create object as reference
j = MBS( "JSON.CreateObjectRef" );
// List fields in current layout
fields = FieldNames ( get(FileName) ; get(LayoutName ));
// how many?
c = ValueCount ( fields );
// make a loop to add field values
r = While ( i = 1 ; i ≤ c ; [ name = GetValue ( fields ; i ); r = MBS( "JSON.AddItemToObject"; j; name; MBS( "JSON.CreateValue"; GetField ( name ) )); i = i + 1 ] ; i );
// format the result
text = MBS( "JSON.Format"; j );
// free json
r = MBS( "JSON.Release"; j )
];
// return result as text
text )
Example result:
{
"First": "John",
"Last": "Miller",
"Group": "",
"Company": "Some Ltd.",
"ID": 12
}
Build a JSON object with an array of objects in one Let:
let([
// build first object
o1 = "{}";
o1 = MBS("JSON.AddStringToObject"; o1; "FirstName"; "Joe");
o1 = MBS("JSON.AddStringToObject"; o1; "LastName"; "Miller");
// build first object
o2 = "{}";
o2 = MBS("JSON.AddStringToObject"; o2; "FirstName"; "Zoe");
o2 = MBS("JSON.AddStringToObject"; o2; "LastName"; "Jones");
// add them to array:
a1 = "[]";
a1 = MBS("JSON.AddItemToArray"; a1; o1);
a1 = MBS("JSON.AddItemToArray"; a1; o2);
// make result
r = "{}";
r = MBS( "JSON.AddItemToObject"; r; "people"; a1 );
r = MBS( "JSON.AddStringToObject"; r; "count"; 2 )
];r)
This function checks for a license.
Created 18th August 2014, last changed 7th February 2023