From 1a09a505973bf137f8c10db680ab644ef0a23e03 Mon Sep 17 00:00:00 2001 From: ewatch Date: Sun, 5 Oct 2025 18:24:07 +0200 Subject: [PATCH 1/3] add GlideJsonPath Example --- Core ServiceNow APIs/GlideJsonPath/README.md | 9 ++++ .../GlideJsonPath/examples.js | 53 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Core ServiceNow APIs/GlideJsonPath/README.md create mode 100644 Core ServiceNow APIs/GlideJsonPath/examples.js diff --git a/Core ServiceNow APIs/GlideJsonPath/README.md b/Core ServiceNow APIs/GlideJsonPath/README.md new file mode 100644 index 0000000000..7f69502e9a --- /dev/null +++ b/Core ServiceNow APIs/GlideJsonPath/README.md @@ -0,0 +1,9 @@ +# Querying JSON with JSONPath to extract values + +GlideJsonPath is a class which can be used to use JSONPath in ServiceNow. It can be useful when working with JSON Payloads, especially highly nested or in general complex structures. + +References: +[RFC 9535: JSONPath: Query Expressions for JSON](https://datatracker.ietf.org/doc/rfc9535/) +[Play with JSONPath outside of ServiceNow](https://jsonpath.com/) +[Good Examples to start with](https://restfulapi.net/json-jsonpath/) +[ServiceNow API Documentation](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideJsonPath/concept/GlideJsonPathAPI.html) \ No newline at end of file diff --git a/Core ServiceNow APIs/GlideJsonPath/examples.js b/Core ServiceNow APIs/GlideJsonPath/examples.js new file mode 100644 index 0000000000..03740bb770 --- /dev/null +++ b/Core ServiceNow APIs/GlideJsonPath/examples.js @@ -0,0 +1,53 @@ +// Run in background script +var 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 + } + } +}; + +var path1 = 'store.book[0].author'; // The author of the first book +var path2 = 'store.book[*].author'; // All authors +var path3 = 'store..price'; // All prices +var path4 = '$..book[?(@.price<10)]'; // All books cheaper than 10 +var path5 = '$..book[?(@.isbn)]'; // All books with an ISBN number +var path6 = '$..*'; // All members of JSON structure + +var gjp = new GlideJsonPath(JSON.stringify(json)); +gs.info('Path: ' + path1 + ' Result: ' + gjp.read(path1)); +gs.info('Path: ' + path2 + ' Result: ' + gjp.read(path2)); +gs.info('Path: ' + path3 + ' Result: ' + gjp.read(path3)); +gs.info('Path: ' + path4 + ' Result: ' + gjp.read(path4)); +gs.info('Path: ' + path5 + ' Result: ' + gjp.read(path5)); +gs.info('Path: ' + path6 + ' Result: ' + gjp.read(path6)); \ No newline at end of file From 8e4bb764c73ba761f8b1748b67c505c29b5df6c2 Mon Sep 17 00:00:00 2001 From: ewatch Date: Sun, 5 Oct 2025 18:27:40 +0200 Subject: [PATCH 2/3] move to subcategory --- Core ServiceNow APIs/GlideJsonPath/{ => Basic-Example}/README.md | 0 .../GlideJsonPath/{ => Basic-Example}/examples.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Core ServiceNow APIs/GlideJsonPath/{ => Basic-Example}/README.md (100%) rename Core ServiceNow APIs/GlideJsonPath/{ => Basic-Example}/examples.js (100%) diff --git a/Core ServiceNow APIs/GlideJsonPath/README.md b/Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md similarity index 100% rename from Core ServiceNow APIs/GlideJsonPath/README.md rename to Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md diff --git a/Core ServiceNow APIs/GlideJsonPath/examples.js b/Core ServiceNow APIs/GlideJsonPath/Basic-Example/examples.js similarity index 100% rename from Core ServiceNow APIs/GlideJsonPath/examples.js rename to Core ServiceNow APIs/GlideJsonPath/Basic-Example/examples.js From 2c16bb5dc9495f97c3d20c2359d92f4d25ddfa11 Mon Sep 17 00:00:00 2001 From: ewatch Date: Sun, 5 Oct 2025 18:30:34 +0200 Subject: [PATCH 3/3] formatting reference list --- .../GlideJsonPath/Basic-Example/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md b/Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md index 7f69502e9a..c2a062042b 100644 --- a/Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md +++ b/Core ServiceNow APIs/GlideJsonPath/Basic-Example/README.md @@ -3,7 +3,7 @@ GlideJsonPath is a class which can be used to use JSONPath in ServiceNow. It can be useful when working with JSON Payloads, especially highly nested or in general complex structures. References: -[RFC 9535: JSONPath: Query Expressions for JSON](https://datatracker.ietf.org/doc/rfc9535/) -[Play with JSONPath outside of ServiceNow](https://jsonpath.com/) -[Good Examples to start with](https://restfulapi.net/json-jsonpath/) -[ServiceNow API Documentation](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideJsonPath/concept/GlideJsonPathAPI.html) \ No newline at end of file +- [RFC 9535: JSONPath: Query Expressions for JSON](https://datatracker.ietf.org/doc/rfc9535/) +- [Play with JSONPath outside of ServiceNow](https://jsonpath.com/) +- [Good Examples to start with](https://restfulapi.net/json-jsonpath/) +- [ServiceNow API Documentation](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideJsonPath/concept/GlideJsonPathAPI.html) \ No newline at end of file