A JSONPath Primer (with Macro Scheduler Examples)

If you’ve ever worked with APIs, web services, or modern applications, you’ve probably bumped into JSON.

And if you’ve ever tried to extract just one value from a JSON response… you’ve probably discovered that JSONPath can feel unintuitive, fiddly, and more complicated than it should be.

You’re not alone.

Even developers find JSONPath awkward at times. That’s why we’ve improved JSONPath support in Macro Scheduler to include filter predicates (?[] ) and the current-node operator (@ ), making it far more powerful and practical.

This article is a simple, practical primer on JSONPath, aimed at everyday Macro Scheduler users who want to get results quickly.


What is JSONPath?

JSONPath is a query language for JSON — similar in spirit to XPath for XML.

Think of it as a way to say:

“From this JSON data, go here… then here… and give me this value.”


When Would You Use JSONPath in Macro Scheduler?

Most commonly:

  • When calling web APIs with HTTPRequest
  • When working with JSON returned by cloud services
  • When parsing data files or API responses

Typical flow:

HTTPRequest  -> returns JSON JSONParse   -> extract specific values Use results in your script 

The JSONParse Command

JSONParse>json_string,json_path,result 
  • json_string   = the JSON text
  • json_path   = the JSONPath expression
  • result   = an array variable that will receive matches

Macro Scheduler also sets:

result_count 

Which tells you how many matches were found.


Important: The $   Root Operator

Since Macro Scheduler v14.5, JSONPath must start with $  .

Example:

$.ip $.people[0].Name 

If you have older scripts, you can enable legacy mode:

Let>JSONPARSE_LEGACY=1 

But we strongly recommend updating paths to use $  .


A Tiny JSON Example

{  "uid" : "1234",  "clients" : ["client1","client2","client3"],  "people" : [     {"Name":"Marcus","Age":"21"},     {"Name":"Dorian","Age":"18"}  ],  "color" : "red",  "size" : 14 } 

Assume this JSON is stored in variable sJSON  .


Getting a Simple Value

Get the UID

JSONParse>sJSON,$.uid,result MessageModal>UID is: %result_1% 

Explanation:

  • $   = root
  • .uid   = property called uid  

Accessing Array Items

First Client (arrays are zero-based)

JSONParse>sJSON,$.clients[0],result MessageModal>Client 1 is %result_1% 

Second Person’s Name

JSONParse>sJSON,$.people[1].Name,result MessageModal>Second name is %result_1% 

Wildcards: Getting Multiple Values

To get all names:

JSONParse>sJSON,$.people[*].Name,result 

Now result   contains multiple entries.

Loop through them:

Let>k=0 Repeat>k   Let>k=k+1   Let>this_name=result_%k%   MessageModal>%this_name% Until>k=result_count 

Using Bracket Notation

Sometimes property names contain dots or special characters.

Instead of:

.people[1].Name 

You can write:

$['people'][1]['Name'] 

Same result — but safer in edge cases.


Introducing Filters (?[ ... ]  )

Filters let you select items based on conditions.

They work on arrays and use:

[email protected] <value 
  • ?[]   = filter block
  • @   = “current item”

Sample Store JSON

{ "store":{   "book":[     {"author":"Nigel Rees","price":8.95},     {"author":"Evelyn Waugh","price":12.99},     {"author":"Herman Melville","isbn":"0-553","price":8.99},     {"author":"J. R. R. Tolkien","isbn":"0-395","price":22.99}   ] } } 

Books Cheaper Than 10

JSONParse>json,$.store.book[[email protected] < 10],cheapBooks MessageModal>Found %cheapBooks_count% cheap books 

Meaning:

  • Look in store.book  
  • For each book, keep it if price < 10  

Books That Have an ISBN

JSONParse>json,$.store.book[[email protected]],withIsbn 

If a property exists, it evaluates as true.


Books by a Specific Author

JSONParse>json,$.store.book[[email protected] == "J. R. R. Tolkien"],tolkien MessageModal>Tolkien book: %tolkien_1% 

Combining Filters and Fields

Titles of books under 15:

JSONParse>json,$.store.book[[email protected] < 15].title,titlesUnder15 

Filter first → then extract .title  .


Logical Operators

OR

JSONParse>json,$.store.book[[email protected] < 10 || @.isbn],cheapOrIsbn 

NOT

JSONParse>json,$.store.book[[email protected]],noIsbn 

Common Mistakes

Forgetting the $  

Wrong:

.people[0].Name 

Correct:

$.people[0].Name 

Forgetting Results Are Arrays

Even if only one match is expected:

result_1 

Not just result  .


Quoting Strings

Always use quotes:

@.author == "Nigel Rees" 

Practical Tip: Build Paths Incrementally

When working with complex JSON:

  1. Start with:
$ 
  1. Add one level at a time:
$.store $.store.book 
  1. Then add filters or fields

This makes troubleshooting much easier.


Why JSONPath Is Worth Learning

Yes — JSONPath is quirky.

But once you grasp a few core ideas:

  • $   = root
  • .   = property
  • [index]   = array element
  • [*]   = all items
  • ?@.   = filter current item

You can extract almost anything from modern APIs.


Cheatsheet

Here's a one page cheatsheet on JSONPath

https://www.mjtnet.com/software/jsonpath_cheat_sheet_macro_scheduler.pdf

Summary

  • JSONPath lets you navigate JSON like a filesystem
  • Macro Scheduler’s JSONParse command supports modern JSONPath with filters
  • Results always return as arrays
  • Filters (?[]  ) and @   unlock powerful selection

If you work with APIs or JSON regularly, mastering these basics will save you hours of trial and error.

Still need help? Contact Us Contact Us