Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jsonata-js/jsonata
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.3
Choose a base ref
...
head repository: jsonata-js/jsonata
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.4
Choose a head ref
  • 12 commits
  • 11 files changed
  • 11 contributors

Commits on Jun 12, 2023

  1. Update overview.md

    The developerWorks video does not exist anymore :(
    jt-nti authored and mattbaileyuk committed Jun 12, 2023
    Copy the full SHA
    3f357ec View commit details

Commits on Aug 10, 2023

  1. Add upper/lower presentation format for am/pm in fromMillis

    Signed-off-by: Alex Woodgate <ajwoodgate@gmail.com>
    Alex Woodgate authored and mattbaileyuk committed Aug 10, 2023
    Copy the full SHA
    7a7f2b5 View commit details
  2. Update construction.md

    tolutaua authored and mattbaileyuk committed Aug 10, 2023
    Copy the full SHA
    69119b1 View commit details

Commits on Sep 4, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e9a97c3 View commit details
  2. Update docs/overview.md

    Looks good
    
    Co-authored-by: Matt Bailey <mattbaileyuk@users.noreply.github.com>
    uw4 and mattbaileyuk committed Sep 4, 2023
    Copy the full SHA
    a2dc4fb View commit details

Commits on Oct 22, 2023

  1. Update sorting-grouping.md

    Yeremenko23 authored and mattbaileyuk committed Oct 22, 2023
    Copy the full SHA
    1df9fc9 View commit details

Commits on Nov 18, 2023

  1. Copy the full SHA
    c947810 View commit details

Commits on Dec 2, 2023

  1. Add new Rust implementation

    jsonata-rs is an actively-developed fork of jsonata-rust.
    ZackKanter authored and mattbaileyuk committed Dec 2, 2023
    Copy the full SHA
    41d14fc View commit details

Commits on Dec 13, 2023

  1. Update numeric-operators.md

    spelling
    stevegroom authored and mattbaileyuk committed Dec 13, 2023
    Copy the full SHA
    d7790e8 View commit details

Commits on Feb 29, 2024

  1. Prevent access to __proto__

    Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
    andrew-coleman authored and mattbaileyuk committed Feb 29, 2024
    Copy the full SHA
    c907b5e View commit details
  2. Check for constructor property

    mattbaileyuk committed Feb 29, 2024
    Copy the full SHA
    335d38f View commit details
  3. Release v2.0.4

    Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
    andrew-coleman committed Feb 29, 2024
    Copy the full SHA
    5731416 View commit details
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#### 2.0.4 Maintenance Release

- Prevent writing to the object prototype or constructor (PR https://github.com/jsonata-js/jsonata/pull/676)
- Add upper/lower presentation format for am/pm in fromMillis (PR https://github.com/jsonata-js/jsonata/pull/644)
- Various documentation additions and corrections

#### 2.0.3 Maintenance Release

- Fix regex termination lexer (PR https://github.com/jsonata-js/jsonata/pull/623)
2 changes: 1 addition & 1 deletion docs/construction.md
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ __Examples__

## Object constructors

In a similar manner to the way arrays can be constructed, JSON objects can also be constructed in the output. At any point in a location path where a field reference is expected, a pair of braces `{}` containing key/value pairs separated by commas, with each key and value separated by a colon: `{key1: value2, key2:value2}`. The keys and values can either be literals or can be expressions. The key must either be a string or an expression that evaluates to a string.
In a similar manner to the way arrays can be constructed, JSON objects can also be constructed in the output. At any point in a location path where a field reference is expected, a pair of braces `{}` containing key/value pairs separated by commas, with each key and value separated by a colon: `{key1: value1, key2:value2}`. The keys and values can either be literals or can be expressions. The key must either be a string or an expression that evaluates to a string.

When an object constructor follows an expression that selects multiple values, the object constructor will create a single object that contains a key/value pair for each of those context values. If an array of objects is required (one for each context value), then the object constructor should immediately follow the dot '.' operator.

2 changes: 1 addition & 1 deletion docs/numeric-operators.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ __Example__
`5 + 2` => `7`


## `-` (Substraction/Negation)
## `-` (Subtraction/Negation)

The subtraction operator subtracts the RHS value from the LHS value to produce the numerical difference It is an error if either operand is not a number.

17 changes: 16 additions & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,22 @@ JSONata is a lightweight query and transformation language for JSON data. Inspir
* Install the module from [NPM](https://www.npmjs.com/package/jsonata)
* Fork the repo on [GitHub](https://github.com/jsonata-js/jsonata)

## Implementations of JSONata

The following are known implementations of JSONata in addition to the primary implementation in JavaScript in the above repo.

|Language|Link|Notes|JSONata version|
|---|---|---|---|
|C|https://github.com/qlyoung/jsonata-c|Runs JSONata in embedded JS engine|1.8.3|
|Go|https://github.com/blues/jsonata-go|Native implementation|1.5.4|
|Go|https://github.com/yxuco/gojsonata|Native implementation| |
|Java|https://github.com/IBM/JSONata4Java|Native implementation| |
|Java|https://github.com/dashjoin/jsonata-java|Native port of reference|2.0.3|
|.NET|https://github.com/mikhail-barg/jsonata.net.native|Native implementation|1.8.5|
|Python|https://github.com/qlyoung/pyjsonata|API bindings based on C bindings|1.8.3|
|Rust|https://github.com/johanventer/jsonata-rust|Implementation work in progress| |
|Rust|https://github.com/Stedi/jsonata-rs|Actively-developed fork of jsonata-rust| |

## Find out more

* Introduction at [London Node User Group meetup](https://www.youtube.com/watch?v=TDWf6R8aqDo)
* IBM developerWorks [Tech Talk](https://www.youtube.com/watch?v=ZRtlkIj0uDY)
2 changes: 1 addition & 1 deletion docs/regex.md
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ Regexes are often used in query predicates (filter expressions) when selecting o

`path.to.object[stringProperty ~> /regex/]`

The `~>` is the [chain operator](control-operators#chain), and its use here implies that the result of `/regex/` is a function. We'll see below that this is in fact the case.
The `~>` is the [chain operator](other-operators#-chain), and its use here implies that the result of `/regex/` is a function. We'll see below that this is in fact the case.

__Examples__

2 changes: 1 addition & 1 deletion docs/sorting-grouping.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ Arrays contain an ordered collection of values. If you need to re-order the val

2. Using the [order-by](path-operators#order-by-) operator.

The [order-by](path-operators#order-by-) operator is a convenient syntax that can used directly in a path expression to sort the result sequences in ascending or descending order. The [`$sort()`](array-functions#sort) function requires more syntax to be written, but is more flexible and supports custom comparator functions.
The [order-by](path-operators#order-by-) operator is a convenient syntax that can be used directly in a path expression to sort the result sequences in ascending or descending order. The [`$sort()`](array-functions#sort) function requires more syntax to be written, but is more flexible and supports custom comparator functions.

## Grouping

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonata",
"version": "2.0.3",
"version": "2.0.4",
"description": "JSON query and transformation language",
"module": "jsonata.js",
"main": "jsonata.js",
7 changes: 7 additions & 0 deletions src/datetime.js
Original file line number Diff line number Diff line change
@@ -904,6 +904,13 @@ const dateTime = (function () {
if (offset === 0 && markerSpec.presentation2 === 't') {
componentValue = 'Z';
}
} else if (markerSpec.component === 'P') {
// §9.8.4.7 Formatting Other Components
// Formatting P for am/pm
// getDateTimeFragment() always returns am/pm lower case so check for UPPER here
if (markerSpec.names === tcase.UPPER) {
componentValue = componentValue.toUpperCase();
}
}
return componentValue;
};
10 changes: 9 additions & 1 deletion src/jsonata.js
Original file line number Diff line number Diff line change
@@ -1293,6 +1293,13 @@ var jsonata = (function() {
}
for(var ii = 0; ii < matches.length; ii++) {
var match = matches[ii];
if (match && (match.isPrototypeOf(result) || match instanceof Object.constructor)) {
throw {
code: "D1010",
stack: (new Error()).stack,
position: expr.position
};
}
// evaluate the update value for each match
var update = await evaluate(expr.update, match, environment);
// update must be an object
@@ -1539,7 +1546,7 @@ var jsonata = (function() {
if (typeof err.token == 'undefined' && typeof proc.token !== 'undefined') {
err.token = proc.token;
}
err.position = proc.position;
err.position = proc.position || err.position;
}
throw err;
}
@@ -1972,6 +1979,7 @@ var jsonata = (function() {
"T1007": "Attempted to partially apply a non-function. Did you mean ${{{token}}}?",
"T1008": "Attempted to partially apply a non-function",
"D1009": "Multiple key definitions evaluate to same key: {{value}}",
"D1010": "Attempted to access the Javascript object prototype", // Javascript specific
"T1010": "The matcher function argument passed to function {{token}} does not return the correct object structure",
"T2001": "The left side of the {{token}} operator must evaluate to a number",
"T2002": "The right side of the {{token}} operator must evaluate to a number",
29 changes: 29 additions & 0 deletions test/implementation-tests.js
Original file line number Diff line number Diff line change
@@ -955,6 +955,35 @@ describe("Tests that are specific to a Javascript runtime", () => {
});
});
});
describe("Expressions that attempt to pollute the object prototype", function() {
it("should throw an error with __proto__", async function() {
const expr = jsonata('{} ~> | __proto__ | {"is_admin": true} |');
expect(
expr.evaluate()
).to.eventually.be.rejected.to.deep.contain({
position: 7,
code: "D1010",
});
});
it("should throw an error with __lookupGetter__", async function() {
const expr = jsonata('{} ~> | __lookupGetter__("__proto__")() | {"is_admin": true} |');
expect(
expr.evaluate()
).to.eventually.be.rejected.to.deep.contain({
position: 7,
code: "D1010",
});
});
it("should throw an error with constructor", async function() {
const expr = jsonata('{} ~> | constructor | {"is_admin": true} |');
expect(
expr.evaluate()
).to.eventually.be.rejected.to.deep.contain({
position: 7,
code: "D1010",
});
});
});
});

describe("Test that yield platform specific results", () => {
16 changes: 16 additions & 0 deletions test/test-suite/groups/function-fromMillis/formatDateTime.json
Original file line number Diff line number Diff line change
@@ -539,6 +539,22 @@
"2018-10-21T13:05:00.000Z"
]
},
{
"function": "#fromMillis",
"category": "Upper case AM/PM presentation",
"description": "am/pm presentation should be set to uppercase AM",
"expr": "$fromMillis(1521801216617, '[F], [D]/[M]/[Y] [h]:[m]:[s] [PN]')",
"data": {},
"result": "friday, 23/3/2018 10:33:36 AM"
},
{
"function": "#fromMillis",
"category": "Lower case AM/PM presentation",
"description": "am/pm presentation should be set to lowercase am",
"expr": "$fromMillis(1521801216617, '[F], [D]/[M]/[Y] [h]:[m]:[s] [Pn]')",
"data": {},
"result": "friday, 23/3/2018 10:33:36 am"
},
{
"function": "#fromMillis",
"category": "error",