Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.GetObjectItem
Queries named item from an object.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 2.7 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
json | A JSON text or reference. | "[1,2,3]" | |
name | The name of the key to query. | "test" | |
AsReference | Whether to return a reference number (1) instead of the JSON text (0). Default is 0 for JSON text. |
0 | Optional |
Result
Returns JSON code.
Description
Queries named item from an object.You still need functions like JSON.GetStringValue to get back the decoded string.
Examples
Create object, add content and pick value:
Let(
[
j = MBS( "JSON.CreateObject");
j = MBS( "JSON.AddStringToObject"; j; "hello"; "world" );
r = MBS( "JSON.GetObjectItem"; j; "hello" )
];
r)
Pick a text from a JSON dictionary:
set $json to "{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}"
set $first to MBS("JSON.GetObjectItem"; $json; "first")
set $firstText to MBS("JSON.GetStringValue"; $first)
display dialog $firstText
Extract error details from JSON:
# JSON in field:
#{
# "error": {
# "message": "Your card's expiration year is invalid.",
# "type": "card_error",
# "param": "exp_year",
# "code": "invalid_expiry_year"
# }
#}
#get it in variable
Set Variable [$json; Value:test::input]
#pick error node
Set Variable [$error; Value:MBS("JSON.GetObjectItem"; $json; "error")]
If [$error = ""]
Show Custom Dialog ["No error"; "No error node in the JSON."]
Else
#get message node
Set Variable [$message; Value:MBS("JSON.GetObjectItem"; $error; "message")]
#decode text
Set Variable [$messageText; Value:MBS("JSON.GetStringValue"; $message)]
#get code node
Set Variable [$code; Value:MBS("JSON.GetObjectItem"; $error; "code")]
#decode text
Set Variable [$codeText; Value:MBS("JSON.GetStringValue"; $code)]
#show result
Show Custom Dialog ["Got error"; "Message: " & $messageText & ¶ & "Code: " & $codeText]
End If
See also
- FM.SQL.JSONRecords
- JSON.AddStringToObject
- JSON.CreateObject
- JSON.FindValueInObjectArray
- JSON.GetObjectItemTree
- JSON.GetObjectItemTreeRef
- JSON.GetObjectName
- JSON.GetObjectSize
- JSON.GetStringValue
Release notes
- Version 11.4
- Fixed a crash in JSON.GetObjectItem with big JSON arrays.
- Version 11.3
- Changed JSON.GetObjectItemTree, JSON.GetObjectItemTreeRef, JSON.AddArrayToArray and JSON.AddItemToArray to ignore empty parameters.
Example Databases
- CURL/Email/IMAP Email List
- CURL/Email/IMAP Email
- CURL/WebServices/TinyURL
- CURL/WebServices/WeatherBit.io test
- JSON/JSON Order Parsing
- JSON/JSON Test
- Win Only/WindowsML
Blog Entries
FileMaker Magazin
This function checks for a license.
Created 18th August 2014, last changed 3th February 2016