JSONata Compatibility¶
jsonatapy aims for 100% compatibility with the JSONata 2.1.0 specification.
Test Suite Overview¶
jsonatapy includes a comprehensive test adapter that runs the complete reference JSONata test suite from the official JavaScript implementation.
Reference Test Suite¶
- Total Tests: 1258
- Passing: 1258 (100%)
- Source: Official jsonata-js repository (v2.1.0) at
tests/jsonata-js/
Current Compatibility Status¶
Results show 100% compatibility with the JSONata 2.1.0 specification.
Test Groups¶
The reference suite is organized into 102 test groups covering all aspects of JSONata:
Core Functionality¶
literals- Literal values (numbers, strings, booleans, null)fields- Field access and navigationcontext- Context variable ($)variables- Variable bindingswildcards- Wildcard selectors
Operators¶
comparison-operators- Equality, inequality, less than, greater thannumeric-operators- Addition, subtraction, multiplication, division, moduloboolean-expressions- AND, OR, NOT operationsstring-concat- String concatenationconditionals- Ternary operator and if-then-else
Arrays¶
array-constructor- Array construction syntaxsimple-array-selectors- Basic array indexing and slicingmultiple-array-selectors- Complex array selectionspredicates- Array filtering with predicatestransforms- Array transformation operations
Functions¶
String Functions:
- function-string - $string()
- function-substring - $substring()
- function-uppercase - $uppercase()
- function-lowercase - $lowercase()
- function-trim - $trim()
- function-length - $length()
- function-split - $split()
- function-join - $join()
- And more...
Numeric Functions:
- function-number - $number()
- function-abs - $abs()
- function-floor - $floor()
- function-ceil - $ceil()
- function-round - $round()
- function-sqrt - $sqrt()
- function-power - $power()
- And more...
Array Functions:
- function-count - $count()
- function-sum - $sum()
- function-max - $max()
- function-min - $min()
- function-average - $average()
- function-append - $append()
- function-reverse - $reverse()
- function-sort - $sort()
- function-distinct - $distinct()
- And more...
Object Functions:
- function-keys - $keys()
- function-lookup - $lookup()
- function-spread - $spread()
- function-merge - $merge()
- function-exists - $exists()
- And more...
Higher-Order Functions:
- function-map - $map()
- function-filter - $filter()
- function-reduce - $reduce()
- function-single - $single()
- function-sift - $sift()
Advanced Features¶
lambdas- Lambda function syntaxclosures- Closure semanticshigher-order-functions- Passing functions as argumentspartial-function-application- Partial applicationtail-recursion- Tail-recursive functionsregex- Regular expression supportencoding- Character encoding functions
Error Handling¶
errors- Error conditions and messagesmissing-paths- Handling undefined pathsnull- Null value handlingparser-recovery- Parser error recovery
Running Compatibility Tests¶
Run All Tests¶
Run Specific Group¶
# Run only literal tests
pytest tests/python/test_reference_suite.py -v -k "literals"
# Run only string function tests
pytest tests/python/test_reference_suite.py -v -k "function-string"
# Run only lambda tests
pytest tests/python/test_reference_suite.py -v -k "lambdas"
Run with Detailed Output¶
# Short traceback format
pytest tests/python/test_reference_suite.py -v --tb=short
# Show only first 10 failures
pytest tests/python/test_reference_suite.py -v --maxfail=10
# Show full diff for failures
pytest tests/python/test_reference_suite.py -v --tb=long
Test Suite Structure¶
The reference test suite uses JSON-based test specifications:
{
"expr": "JSONata expression",
"dataset": "dataset0",
"bindings": {"var": "value"},
"result": <expected result>
}
Each test can specify:
- result: Expected successful result
- undefinedResult: Result should be undefined
- code: Expected error code (e.g., "T2001")
- error: Expected error object
- timelimit: Timeout in milliseconds
- depth: Maximum recursion depth
Improving Compatibility¶
If you find a compatibility issue:
-
Run the specific test group to isolate the problem:
-
Check the test case in
tests/jsonata-js/test/test-suite/groups/group_name/ -
File an issue on GitHub with:
- Test group and case number
- Expression that fails
- Expected vs actual result
-
Error message (if any)
-
Submit a PR with the fix:
- Update Rust implementation
- Verify test passes
- Run full suite to check for regressions
Resources¶
- Reference Implementation: https://github.com/jsonata-js/jsonata
- JSONata Specification: https://docs.jsonata.org/
- Test Suite Source:
tests/jsonata-js/test/test-suite/ - JSONata Exerciser: https://try.jsonata.org/ (for testing expressions)