You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Casts the arg parameter to a string using the following casting rules
[...]
All other values are converted to a JSON string using the JSON.stringify function
If an object being stringified has a property named toJSON whose value is a function, then the toJSON() method customizes JSON stringification behavior: instead of the object being serialized, the value returned by the toJSON() method when called will be serialized.
Moment.js' .toJSON() is invoked. This results in JSON.stringify(someISOString) which results in an ISO string wrapped in double quotes being concatinated with the & operator.
The text was updated successfully, but these errors were encountered:
jhorbulyk
changed the title
Serialization of the $moment() object is very inconsitent
Serialization of the $moment() object is very inconsistent
Feb 28, 2018
The short term solution is to have @khanzadyan document the fact that integrators writing JSONata must stringify all moment() objects and to tell QA that stringifying moment() directly is a test case with undefined behavior.
Otherwise, there are the following options:
Disable direct stringification of moment() in jsonata-moment by having moment's .toJSON() throw an exception and by throwing an exception if the end result of an evaluation is a moment() object.
Make the JSONata stringification of moment() objects well defined. In order to do that, both of the following need to be completed:
JSONata $string() function should be modified so that when called on an object, it calls a toJsonataString() function if it exists.
We modify jsonataMoment so that if the evaluated result is a moment object, we stringify that object as the last step of the evaluation process.
Consider the following scenarios:
It would be nice if this was more consistent so that people don't get confused.
The reason why this is happening is as follows:
$moment()
evaulates to an object, not a string. If a JSONata expression writer wants a string, they should use$moment().format()
.moment()
object is stringified with moment's.toString()
functionmoment()
object is stringified with moment's.valueOf()
operator&
operator is applied. As per the documentation:$string()
operator is applied. As per the documentation:JSON.stringify()
is applied. As per the documentation:.toJSON()
is invoked. This results inJSON.stringify(someISOString)
which results in an ISO string wrapped in double quotes being concatinated with the&
operator.The text was updated successfully, but these errors were encountered: