JSON.Query
----------

Performs a JSON Path query.

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

MBS( "JSON.Query"; JSON; Query; Flags ) 

**MBS**( **"JSON.Query";** /\* Performs a JSON Path query. \*/  
**$JSON**; /\* A JSON text or reference.e.g. "{\\"people\\":\[{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}\]}" \*/   
**$Query**; /\* The query string. \*/   
**$Flags**) /\* The flags. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| JSON | A JSON text or reference. | "{\\"people\\":\[{\\"first\\":\\"Christian\\",\\"last\\":\\"Schmitz\\",\\"city\\":\\"Nickenich\\"}\]}" |
| Query | The query string. |  |
| Flags | The flags. |  |

### Result

Returns JSON or error.

### Description

Performs a JSON Path query.  
Evaluates the root value against the JSONPath expression and returns an array of values or normalized path expressions.  
  
Returns a JSON with an array containing either values or normalized path expressions matching the JSONPath expression, or an empty array if there is no match.  
  
To learn more about JSONPath, please check this website:  
<https://goessner.net/articles/JsonPath/>  
  
Learn more about the JSONPath implementation here:  
<https://danielaparker.github.io/JsonCons.Net/articles/JsonPath/JsonConsJsonPath.html>  
  
See also [JSON.Replace](JSONReplace.md) to replace found values with new values.  
### Examples

Query input:

 let(\[  
 json = "{\\"test\\":123}";  
 result = MBS ("JSON.Query"; json; "$"; 0)  
\]; result)  
<small>  
Example result:   
\[ { "test" : 123 } \] </small>Query with regular expression:

 let(\[  
json = "{  
 \\"store\\": {  
 \\"book\\": \[  
 {  
 \\"category\\": \\"reference\\",   
 \\"author\\": \\"Nigel Rees\\",   
 \\"title\\": \\"Sayings of the Century\\",   
 \\"price\\": 8.95   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Evelyn Waugh\\",   
 \\"title\\": \\"Sword of Honour\\",   
 \\"price\\": 12.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Herman Melville\\",   
 \\"title\\": \\"Moby Dick\\",   
 \\"isbn\\": \\"0-553-21311-3\\",   
 \\"price\\": 8.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"J. R. R. Tolkien\\",   
 \\"title\\": \\"The Lord of the Rings\\",   
 \\"isbn\\": \\"0-395-19395-8\\",   
 \\"price\\": 22.99   
 }  
 \],   
 \\"bicycle\\": {  
 \\"color\\": \\"red\\",   
 \\"price\\": 19.95   
 }  
 }  
}";  
// All books whose author's name starts with Evelyn  
result = MBS ("JSON.Query"; json; "$.store.book\[?(@.author =~ /Evelyn.\*?/)\]"; 0)  
\]; result)  
<small>  
Example result:   
\[ { "category" : "fiction" , "author" : "Evelyn Waugh" , "title" : "Sword of Honour" , "price" : 12.99 } \] </small>Query all keys:

 let(\[  
json = "{  
 \\"store\\": {  
 \\"book\\": \[  
 {  
 \\"category\\": \\"reference\\",   
 \\"author\\": \\"Nigel Rees\\",   
 \\"title\\": \\"Sayings of the Century\\",   
 \\"price\\": 8.95   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Evelyn Waugh\\",   
 \\"title\\": \\"Sword of Honour\\",   
 \\"price\\": 12.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Herman Melville\\",   
 \\"title\\": \\"Moby Dick\\",   
 \\"isbn\\": \\"0-553-21311-3\\",   
 \\"price\\": 8.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"J. R. R. Tolkien\\",   
 \\"title\\": \\"The Lord of the Rings\\",   
 \\"isbn\\": \\"0-395-19395-8\\",   
 \\"price\\": 22.99   
 }  
 \],   
 \\"bicycle\\": {  
 \\"color\\": \\"red\\",   
 \\"price\\": 19.95   
 }  
 }  
}";  
// All keys in the second book  
result = MBS ("JSON.Query"; json; "keys($.store.book\[1\])\[\*\]"; 0)  
\]; result)  
<small>  
Example result:   
\[ "category" , "author" , "title" , "price" \] </small>Find all books matching a criteria and return list of matching title values:

 let(\[  
json = "{  
 \\"store\\": {  
 \\"book\\": \[  
 {  
 \\"category\\": \\"reference\\",   
 \\"author\\": \\"Nigel Rees\\",   
 \\"title\\": \\"Sayings of the Century\\",   
 \\"price\\": 8.95   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Evelyn Waugh\\",   
 \\"title\\": \\"Sword of Honour\\",   
 \\"price\\": 12.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"Herman Melville\\",   
 \\"title\\": \\"Moby Dick\\",   
 \\"isbn\\": \\"0-553-21311-3\\",   
 \\"price\\": 8.99   
 },   
 {  
 \\"category\\": \\"fiction\\",   
 \\"author\\": \\"J. R. R. Tolkien\\",   
 \\"title\\": \\"The Lord of the Rings\\",   
 \\"isbn\\": \\"0-395-19395-8\\",   
 \\"price\\": 22.99   
 }  
 \],   
 \\"bicycle\\": {  
 \\"color\\": \\"red\\",   
 \\"price\\": 19.95   
 }  
 }  
}";  
// Find all book titles with price &gt; 10  
result = MBS ("JSON.Query"; json; "$.store\[@.book\[?(@.price &gt; 10)\].title\]"; 0)  
\]; result)  
<small>  
Example result:   
\[ "Sword of Honour" , "The Lord of the Rings" \] </small>Find matching entry in JSON Array of Objects:

 MBS ( "JSON.Query";  
"\[ {\\"test\\":\\"abc\\", \\"ID\\": 1}, {\\"test\\":\\"Hello\\", \\"ID\\": 2} \]";  
"$\[?(@.test == 'Hello')\]" )  
Find matching entry in JSON Array of Objects with two criterias:

 MBS ( "JSON.Query";  
"\[ {\\"test\\":\\"abc\\", \\"ID\\": 1}, {\\"test\\":\\"Hello\\", \\"ID\\": 2} \]";  
"$\[?(@.test == 'Hello' || @.test == 'abc')\]" )  
<small>  
Example result:   
\[ { "test" : "abc" , "ID" : 1 }, { "test" : "Hello" , "ID" : 2 } \] </small>### See also

- [JSON.FilterObjectArray](JSONFilterObjectArray.md)
- [JSON.Import](JSONImport.md)
- [JSON.Replace](JSONReplace.md)
- [JSON.ReplaceEvaluate](JSONReplaceEvaluate.md)
- [JSON.Search](JSONSearch.md)
- [JSON.ToCSV](JSONToCSV.md)
- [LDAP.JSON](LDAPJSON.md)

### Release notes

- **Version 13.5**
    - Added [JSON.Query](https://www.mbsplugins.eu/JSONQuery.shtml) function for JSON Path queries.

### Example Databases

- [JSON/JSON Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Query.shtml#1ScriptAnchor_)

### Blog Entries

- [Functions in JSON Query](https://www.mbsplugins.de/archive/2023-12-05/Functions_in_JSON_Query/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 13.5](https://www.mbsplugins.de/archive/2023-11-28/New_in_MBS_FileMaker_Plugin_13/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 13.5 für Claris FileMaker](https://www.mbsplugins.de/archive/2023-11-07/Neues_MBS_Plugin_135_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 13.5 for Claris FileMaker](https://www.mbsplugins.de/archive/2023-11-07/MBS_Plugin_135_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [Using JSONPath in FileMaker](https://www.mbsplugins.de/archive/2023-10-18/Using_JSONPath_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [JSON Query in FileMaker](https://www.mbsplugins.de/archive/2023-09-29/JSON_Query_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.5pr1](https://www.mbsplugins.de/archive/2023-09-26/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

Created 17th September 2023 , last changed 10th January 2024

  
[JSON.Parse](JSONParse.md) - [JSON.Release](JSONRelease.md)

[HTML Version](JSONQuery.shtml)