πŸ“ JSONata Prompt Rules

When writing JSONata code, please follow these rules:

βœ… Allowed

  • Use only features documented on docs.jsonata.org
  • Define helper functions with :=
    ```jsonata $foo := function($x){ $x + 1 }

Wrap multiple statements in ( … )

Use filters $[ ... ] and projections .( … )

Use standard functions only: $map, $reduce, $each, $exists, $lookup, $substring, $number, $string, $match, $replace, $length, …

Use regex literals /.../i inside $match or $replace

Use ternary conditionals cond ? valueIfTrue : valueIfFalse

Assign variables inside projections

$[type="FamilyInstance"].( $sym := $getSym(parent.id); { "id": id, "symName": $sym.name } )

🚫 Not Allowed

❌ Functions not in docs ($test, $split, $join, etc.)

❌ JavaScript-like constructs (let, const, if (…) { … })

❌ Inline comments inside JSONata code blocks

❌ Stray semicolons outside of ( … ) blocks

❌ Hidden state or order-dependent tricks

βœ… Example Request

β€œWrite a JSONata query that filters FamilyInstances with a FamilySymbol name starting with NLRS, extracts assemblyCode, and returns {id, name, assemblyCode}. Use $match for regex, $lookup for dynamic keys, and put everything in a ( … ) block.”