Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONATA undefined in Internet explorer #158

Closed
hufedebe opened this issue Feb 19, 2018 · 7 comments · Fixed by #243

Comments

@hufedebe
Copy link

@hufedebe hufedebe commented Feb 19, 2018

Hello everyone,

I just did a project heavily using JSONata, and it works perfectly well in Mozilla, Chrome, and Edge. But it doesnt work in Internet Explorer, it just shows the following error:

"SCRIPT5009: 'jsonata' is undefined", please help.

I'm just using it like this:

jsonata('string').evaluate(data);

@hufedebe hufedebe changed the title JSONATA undfined in Internet explorer JSONATA undefined in Internet explorer Feb 19, 2018
@andrew-coleman

This comment has been minimized.

Copy link
Member

@andrew-coleman andrew-coleman commented Feb 21, 2018

I suspect this is an ES6 issue. Have you tried using the babel transpiled version jsonata-es5.js?

@hufedebe

This comment has been minimized.

Copy link
Author

@hufedebe hufedebe commented Mar 1, 2018

Thank you Andrew, it almost works. In one part of the code i'm extracting properties normally with jsonata: info = jsonata('[xml.resume.{"date" : date, "field2": field2}]').evaluate(data); and then I want to add a counter, because its several objects, so I have this code: info = jsonata('$ ~> $map(function($v, $i) {$merge([{'count': $i+1}, $v])})').evaluate(info);. But that changes info into an Object Generator (according to Internet Explorer): [object Generator]. before I merge it with the count, it does output a correct object though, do I have to change the merge function? @andrew-coleman

@andrew-coleman

This comment has been minimized.

Copy link
Member

@andrew-coleman andrew-coleman commented Mar 1, 2018

Does this same code evaluate correctly in other browsers? I don't have Internet Explorer (or Windows) so there will be a lack of testing on my part here.

@hufedebe

This comment has been minimized.

Copy link
Author

@hufedebe hufedebe commented Mar 1, 2018

Yes, in all other browsers it works fine, its having problems in Internet Explorer - it creates the [object Generator] instead of adding the "count" attribute to the existing object. Other than that, the other jsonata parts work well. its just the adding a "count" attribute to the existing object that works incorrectly, is there another way of obtaining the same result without using "$ ~> $map(function($v, $i) {$merge([{'count': $i+1}, $v])})"? @andrew-coleman

@s100

This comment has been minimized.

Copy link
Contributor

@s100 s100 commented May 25, 2018

@hufedebe Can you provide minimal reproduction steps for this issue? At minimum please can you show us your HTML, your JavaScript, what version of JSONata you are using, and what version of Internet Explorer you are using.

@s100

This comment has been minimized.

Copy link
Contributor

@s100 s100 commented Jun 25, 2018

A minimal reproduction is:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>JSONata test</title>
        <script src="jsonata-es5.js"></script>
        <script>
            const output = jsonata("$map([1..5], $string)").evaluate({});
            console.log(output)
        </script>
    </head>
    <body></body>
</html>

In Chrome, this outputs an array ["1", "2", "3", "4", "5"]. IE11, this outputs the [object Generator] which was mentioned. Still working on why...

@s100

This comment has been minimized.

Copy link
Contributor

@s100 s100 commented Jun 25, 2018

It seems that the problem here is in how we detect whether a value returned from a JSONata function is iterable or not. This heuristic works fine on e.g. Chrome but fails on IE11. I have worked out a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.