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:
9.3
9.4
9.5
10.0
10.1
10.2
10.3
10.4
10.5
10.6
Statistic
FMM
Blog
JSON.AddItemToObject
Adds a new entry to the object with the given name and value.
| Component | Version | macOS | Windows | Linux | Server | FileMaker iOS SDK |
| JSON | 2.7 | Yes | Yes | Yes | Yes | Yes |
Parameters
| 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 |
Result
Returns JSON code.
Description
Adds a new entry to the object with the given name and value.With version 6, you can pass several parameters to add several entries to the object.
When adding to a JSON reference, the function returns that reference number.
Examples
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
}
See also
- CURL.SetupOAuth
- JSON.AddFalseToObject
- JSON.AddNumberToObject
- JSON.AddStringToObject
- JSON.AddTrueToObject
- JSON.CreateArrayRef
- JSON.CreateObject
- JSON.CreateObjectRef
- JSON.Format
- JSON.Release
Example Databases
- JSON/JSON Test
- Mac and iOS/MapKit/MapKit Snapshots
- Mac and iOS/MapKit/MapView BeeExample
- Mac and iOS/MapKit/MapView Click Polygons
Blog Entries
- With JSON in excellent form
- Fun with While function in FileMaker
- JSON with large integers
- Generate JSON with MBS Plugin
FileMaker Magazin
Created 18th August 2014, last changed 22nd July 2019
JSON.AddItemToArray - JSON.AddNullToObject
Feedback: Report problem or ask question.
Links
MBS Xojo Plugins