jsonata-js/jsonata

Breaking change between 1.8.6 and 2.0.3 - empty arrays

GeoffThorpeFT opened this issue · 1 comments

I'm using JSONata to reformat rows from an API. That API either returns a valid array of JSON objects or [] if no results are found.

For ease of explanation let us assume my JSONata transformation string is $.{"geoff","this is a test"} with the [] response rom the my API.

When I run with the [v1.8.6 JSONata](API https://www.npmjs.com/package/jsonata/v/1.8.6) I get:
[]

When I run with the [v2.0.3 JSONata](API https://www.npmjs.com/package/jsonata/v/2.0.3) I get:
[{}]

However, I note with some surprise that the try JSONata site shows [] for both versions of the API

Here my call to JSONata within my nodejs v14 app:

		const filtered = [];
		const jsonataTransformationString = "{\"geoff\",\"this is a test\"}";
		const transformationExpression = jsonata(
			`$.${jsonataTransformationString}`,
		);
		transformed = toArray(transformationExpression.evaluate(filtered));

I suspect that the {} in the 2.0.3 version is a representation of the unawaited promise. remember v2 is async. also remember that breaking changes are allowed with a major version increment.

assumptions

  • the expression should be $.{"geoff":"this is a test"} as the one you gave is invalid
  • toArray is what is wrapping your result in an array, and the return value from "evaluate" is undefined and Promise respectively.