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
JSON.GetPathItem
Queries value from JSON path.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 6.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
json | A JSON text or reference. | "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}" | |
Path | The path through the json hierarchy as list. For object, pass name of item to choose. For array pass index. |
"people¶0¶last" | |
Flags | Pass 1 to return as value, e.g. text or number. Pass 0 (or nothing) to return as JSON. Add 2 to return empty in case of error, e.g. value not existing. (new in 7.5) |
Optional |
Result
Returns value or error.
Description
Queries value from JSON path.The path describes the way through the hierarchy to find the JSON node to return.
Result can be JSON or the value.
If path ends with # in an array, we return number of elements.
Implemented FileMaker syntax in v12.4 for JSON element get/set like in JSONGetElement function, so you can use dot notation, [array index] or quoted text in brackets.
Examples
Query people:
MBS( "JSON.GetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people")
Query people -> first entry:
MBS( "JSON.GetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people¶0")
Query people -> first entry -> last name:
MBS( "JSON.GetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people¶0¶last")
Query IP via ipinfo.io:
Go to Layout [“Table”]
New Record/Request
#Start new session
Set Variable [$curl; Value:MBS("CURL.New")]
#Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "http://ipinfo.io")]
#RUN now
Set Variable [$result; Value:MBS("CURL.Perform"; $curl)]
#Check result
Set Field [Table::DebugLog; MBS("CURL.GetDebugMessages"; $curl)]
Set Field [Table::Result; MBS("CURL.GetResultAsText"; $curl; "UTF8")]
If [$result = "OK"]
#Check HTTP error code
Set Variable [$response; Value:MBS("CURL.GetResponseCode"; $curl)]
If [$response = 200]
#Query values from JSON
Set Variable [$json; Value:MBS( "JSON.Parse"; Table::Result )]
Set Field [Table::IP; MBS("JSON.GetPathItem"; $json; "ip"; 1)]
Set Field [Table::Hostname; MBS("JSON.GetPathItem"; $json; "hostname"; 1)]
Set Field [Table::City; MBS("JSON.GetPathItem"; $json; "city"; 1)]
Set Field [Table::Region; MBS("JSON.GetPathItem"; $json; "region"; 1)]
Set Field [Table::Country; MBS("JSON.GetPathItem"; $json; "country"; 1)]
Set Field [Table::Location; MBS("JSON.GetPathItem"; $json; "loc"; 1)]
Set Field [Table::Company or Provider; MBS("JSON.GetPathItem"; $json; "org"; 1)]
Set Variable [$r; Value:MBS( "JSON.Release"; $json )]
End If
End If
#Cleanup
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Commit Records/Requests [No dialog]
Query number of entries in array:
MBS( "JSON.GetPathItem"; "{\"IDs\":[1,5,8,2,5]}"; "IDs¶#")
Example result: 5
Try FileMaker syntax with object and array:
MBS( "JSON.GetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people[0]last")
Example result: "Schmitz"
Try FileMaker syntax with objects:
MBS( "JSON.GetPathItem"; "{\"people\":{\"best\":{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}}}"; ".people.best.first"; 3)
Example result: Christian
Try FileMaker syntax with an array:
MBS( "JSON.GetPathItem"; "[1,2,3]"; ".[2]")
Example result: 3
Try FileMaker syntax with objects in brackets:
MBS( "JSON.GetPathItem"; "{\"people\":{\"best.friend\":{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}}}"; "['people']['best.friend']['first']"; 3)
Example result: Christian
See also
- CoreML.PredictionFromFeatures
- CURL.GetResponseCode
- CURL.GetResultAsText
- CURL.New
- CURL.Perform
- JSON.DeleteItemFromArray
- JSON.GetArraySize
- JSON.Release
- JSON.SetPathItem
- MetaDataQuery.AttributesForFile
Release notes
- Version 12.5
- Fixed a regression in JSON.GetPathItem and JSON.SetPathItem to restore functionality, where you just grab an array item with just an index.
- Version 12.4
- Improved JSON.SetPathItem and JSON.GetPathItem functions to accept FileMaker's style for object/array accessing.
- Version 10.3
- Fixed JSON.GetPathItem to not complain about out of bounds if option value 2 is used.
- Version 8.1
- Fixed JSON.GetPathItem returning numbers with dot incorrectly for non-english localization. Broken in 7.5.
- Version 7.5
- Added flag for JSON.GetPathItem to avoid returning error for missing keys.
Example Databases
- Barcode/Swiss QR-Code for invoices/Swiss QR-Code for invoices ISO 20022
- CURL/Email/IMAP Email
- CURL/WebServices/CURL FMS Admin API v18
- CURL/WebServices/ebay webservice/ebay Webservice
- CURL/WebServices/Query IP and Country
- CURL/WebServices/WeatherBit.io test
- Mac and iOS/Machine Learning/Core Image Detection
- Mac and iOS/Machine Learning/Core ML Photos
- Mac and iOS/MapKit/MapView BeeExample
- Mac only/ImageCapture/Camera Import
Blog Entries
- New in MBS FileMaker Plugin 13.3
- MBS FileMaker Plugin, version 12.5pr4
- MBS FileMaker Plugin, version 12.4pr4
- Recursive Folder Copy Script
- With JSON in excellent form
- Sum up values in JSON with MBS FileMaker Plugin
- Query URL from downloaded file
- Comparing Base Elements Plugin to MBS FileMaker Plugin
- Face detection via CoreImage in FileMaker
- Query geolocation in FileMaker via MBS Plugin and Google Maps API
FileMaker Magazin
This function checks for a license.
Created 3th February 2016, last changed 3th January 2023
