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

Using JSON.stringify with an ExpandoObject returns "{}" instead of useful results #855

Closed
craigfowler opened this issue Apr 1, 2021 · 2 comments · Fixed by #862
Closed

Comments

@craigfowler
Copy link

I have created a small repo which contains a reproduction case for this. To see the issue for yourself clone it and run it using dotnet test. This might be a duplicate of #347, although I want to specifically point out the behaviour relating to ExpandoObject instead of a statically-typed class instance.

If an ExpandoObject is added into a Jint environment via SetValue & subsequently an attempt is made to JSON.stringify(theExpando), this will always produce a result of "{}". Instead I think it should produce appropriate results for the state of that expando object.

This is particularly troublesome because of the behaviour of JSON.parse. When using JSON.parse('{"foo":5,"bar":"A string"}'), Jint will return an expando back to "the .NET world". That's understandable; I don't think any other behaviour would make any sense. Unfortunately, that returned object then can't be round-tripped back to JSON by executing JS via Jint, because of this issue.

@craigfowler
Copy link
Author

I forgot to mention, one of the test cases in the repro repository does pass. It shows how it stringifies correctly if you give Jint a Dictionary<string,object>. It's possible to convert expandos to that, so that might be a viable workaround for those who run into this.

@ayende
Copy link
Contributor

ayende commented Apr 2, 2021

Note that this means that Jint will have to understand IDynamicObject to support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants