JSON.GetPathItem
----------------

Queries value from JSON path.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JSON](component_JSON.md) | [6.1](newinversion61.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JSON.GetPathItem"; JSON; Path { ; Flags } ) 

**MBS**( **"JSON.GetPathItem";** /\* Queries value from JSON path. \*/  
**$JSON**; /\* A JSON text or reference.e.g. "{\\"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.e.g. "people¶0¶last" \*/   
**$Flags**) /\* Optional; 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) \*/ 

### 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 -&gt; first entry:

 MBS ( "JSON.GetPathItem"; "{\\"people\\":\[{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}\]}"; "people¶0")  
Query people -&gt; first entry -&gt; 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](CURLNew.md)")\]  
\#Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)   
Set Variable \[$result ; Value:MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; "http://ipinfo.io")\]  
\#RUN now   
Set Variable \[$result ; Value:MBS ("[CURL.Perform](CURLPerform.md)"; $curl )\]  
\#Check result   
Set Field \[Table::DebugLog ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl )\]  
Set Field \[Table::Result ; MBS ("[CURL.GetResultAsText](CURLGetResultAsText.md)"; $curl ; "UTF8")\]  
If \[$result = "OK"\]  
 #Check HTTP error code  
 Set Variable \[$response ; Value:MBS ("[CURL.GetResponseCode](CURLGetResponseCode.md)"; $curl )\]  
 If \[$response = 200\]  
 #Query values from JSON  
 Set Variable \[$json ; Value:MBS ( "[JSON.Parse](JSONParse.md)"; 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](JSONRelease.md)"; $json )\]  
 End If  
End If  
\#Cleanup   
Set Variable \[$result ; Value:MBS ("[CURL.Release](CURLRelease.md)"; $curl )\]  
Commit Records/Requests \[No dialog\]  
Query number of entries in array:

 MBS ( "JSON.GetPathItem"; "{\\"IDs\\":\[1,5,8,2,5\]}"; "IDs¶#")  
<small>  
Example result: 5</small>Try FileMaker syntax with object and array:

 MBS ( "JSON.GetPathItem"; "{\\"people\\":\[{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}\]}"; "people\[0\]last")  
<small>  
Example result: "Schmitz"</small>Try FileMaker syntax with objects:

 MBS ( "JSON.GetPathItem"; "{\\"people\\":{\\"best\\":{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}}}"; ".people.best.first"; 3)  
<small>  
Example result: Christian</small>Try FileMaker syntax with an array:

 MBS ( "JSON.GetPathItem"; "\[1,2,3\]"; ".\[2\]")  
<small>  
Example result: 3</small>Try FileMaker syntax with objects in brackets:

 MBS ( "JSON.GetPathItem"; "{\\"people\\":{\\"best.friend\\":{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}}}"; "\['people'\]\['best.friend'\]\['first'\]"; 3)  
<small>  
Example result: Christian</small>### See also

- [CURL.GetDebugMessages](CURLGetDebugMessages.md)
- [CURL.GetResponseCode](CURLGetResponseCode.md)
- [CURL.GetResultAsText](CURLGetResultAsText.md)
- [CURL.New](CURLNew.md)
- [CURL.Perform](CURLPerform.md)
- [CURL.Release](CURLRelease.md)
- [CURL.SetOptionURL](CURLSetOptionURL.md)
- [JSON.GetArraySize](JSONGetArraySize.md)
- [JSON.Parse](JSONParse.md)
- [MetaDataQuery.AttributesForFile](MetaDataQueryAttributesForFile.md)

### Release notes

- **Version 14.3**
    - Fixed [JSON.GetPathItem](https://www.mbsplugins.eu/JSONGetPathItem.shtml) to not return error for invalid JSON if flag 2 is used.
- **Version 12.5**
    - Fixed a regression in [JSON.GetPathItem](https://www.mbsplugins.eu/JSONGetPathItem.shtml) and [JSON.SetPathItem](https://www.mbsplugins.eu/JSONSetPathItem.shtml) to restore functionality, where you just grab an array item with just an index.
- **Version 12.4**
    - Improved [JSON.SetPathItem](https://www.mbsplugins.eu/JSONSetPathItem.shtml) and [JSON.GetPathItem](https://www.mbsplugins.eu/JSONGetPathItem.shtml) functions to accept FileMaker's style for object/array accessing.
- **Version 10.3**
    - Fixed [JSON.GetPathItem](https://www.mbsplugins.eu/JSONGetPathItem.shtml) to not complain about out of bounds if option value 2 is used.
- **Version 8.1**
    - Fixed [JSON.GetPathItem](http://www.mbsplugins.eu/JSONGetPathItem.shtml) returning numbers with dot incorrectly for non-english localization. Broken in 7.5.
- **Version 7.5**
    - Added flag for [JSON.GetPathItem](http://www.mbsplugins.eu/JSONGetPathItem.shtml) to avoid returning error for missing keys.

### Example Databases

- [CURL/Email/IMAP Email List](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email%20List.shtml#1ScriptAnchor_)
- [CURL/WebServices/CURL FMS Admin API v17](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/WebServices/CURL%20FMS%20Admin%20API%20v17.shtml#1ScriptAnchor_)
- [CURL/WebServices/Query IP and Country](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/WebServices/Query%20IP%20and%20Country.shtml#1ScriptAnchor_)
- [CURL/WebServices/WeatherBit.io test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/WebServices/WeatherBit.io%20test.shtml#3ScriptAnchor_)
- [JSON/JSON Benchmark](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Benchmark.shtml#5ScriptAnchor_)
- [Mac and iOS/Data Detector](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/Data%20Detector.shtml#2ScriptAnchor_)
- [Mac and iOS/Machine Learning/Core Image Detection](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/Machine%20Learning/Core%20Image%20Detection.shtml#1ScriptAnchor_)
- [Mac and iOS/Machine Learning/Core ML Photos](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/Machine%20Learning/Core%20ML%20Photos.shtml#6ScriptAnchor_)
- [Mac and iOS/MapKit/MapView BeeExample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/MapKit/MapView%20BeeExample.shtml#5ScriptAnchor_)
- [Mac only/ImageCapture/Camera Import](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20only/ImageCapture/Camera%20Import.shtml#5ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 8 - Weather data with JSON](https://www.mbsplugins.de/archive/2024-12-08/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MQTT in FileMaker](https://www.mbsplugins.de/archive/2024-06-25/MQTT_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [JSON Replace with evaluate](https://www.mbsplugins.de/archive/2024-05-06/JSON_Replace_with_evaluate/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 13.3](https://www.mbsplugins.de/archive/2023-07-25/New_in_MBS_FileMaker_Plugin_13/monkeybreadsoftware_blog_filemaker)
- [Recursive Folder Copy Script](https://www.mbsplugins.de/archive/2021-11-12/Recursive_Folder_Copy_Script/monkeybreadsoftware_blog_filemaker)
- [With JSON in excellent form](https://www.mbsplugins.de/archive/2019-11-16/With_JSON_in_excellent_form/monkeybreadsoftware_blog_filemaker)
- [Sum up values in JSON with MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2018-05-11/Sum_up_values_in_JSON_with_MBS/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [Face detection via CoreImage in FileMaker](https://www.mbsplugins.de/archive/2017-07-23/Face_detection_via_CoreImage_i/monkeybreadsoftware_blog_filemaker)
- [Query geolocation in FileMaker via MBS Plugin and Google Maps API](https://www.mbsplugins.de/archive/2017-01-25/Query_geolocation_in_FileMaker/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2025, Seite 23 bis 24](https://filemaker-magazin.de/neuigkeit/4286-Appetithappen-FMM_202502)
- [Ausgabe 5/2022, Seite 28](https://filemaker-magazin.de/neuigkeit/4196-Appetithappen-FMM_202205)
- [Ausgabe 2/2022, Seite 33](https://filemaker-magazin.de/neuigkeit/4174-Appetithappen-FMM_202202)
- [Ausgabe 6/2021, Seite 23](https://filemaker-magazin.de/neuigkeit/4165-Appetithappen-FMM_202106)
- [Ausgabe 5/2020, Seite 17](https://filemaker-magazin.de/neuigkeit/4110-Appetithappen-FMM_202005)

This function checks for a license.

Created 3th February 2016 , last changed 3th January 2023

  
[JSON.GetObjectSize](JSONGetObjectSize.md) - [JSON.GetStringValue](JSONGetStringValue.md)

[HTML Version](JSONGetPathItem.shtml)