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

JSON.stringify doesn't work for external objects #69

Closed
alveko opened this issue Dec 9, 2018 · 6 comments
Closed

JSON.stringify doesn't work for external objects #69

alveko opened this issue Dec 9, 2018 · 6 comments

Comments

@alveko
Copy link

alveko commented Dec 9, 2018

When trying to call JSON.stringify(request), where request is an external object, the result is null.

@xeioex
Copy link
Contributor

xeioex commented Dec 9, 2018

Hi @alveko,

You can use a helper function njs.dump() to see some details of the request object.

The problem with externals is that as of now, they are semi-Objects. It is not possible to use them interchangeably with native js Objects.

In the future I plan to get rid of the external type, converting the external prototypes to native Objects. But, that is not that easy.

@reyou
Copy link

reyou commented Dec 17, 2018

Hello @xeioex ,

Sorry to bombard you with questions today, but how do we supposed to use njs.dump()?

I tried following ways, but could not figure out how to read content:

njs.dump();
req.error(njs.dump());
req.error(JSON.stringfy(njs.dump()));

Could you please help?

@xeioex
Copy link
Contributor

xeioex commented Dec 17, 2018

@reyou,

njs.dump() is similar to JSON.stringify() but it is a bit more verbose (for example it can dump (== 'stringify') external objects like r)

For example you can return it as a body of the http reply:
r.return(200, njs.dump(r))

@reyou
Copy link

reyou commented Dec 17, 2018

This works great, thanks a lot!

@xeioex
Copy link
Contributor

xeioex commented Apr 18, 2019

closed as duplicate of #16

@xeioex xeioex closed this as completed Apr 18, 2019
@xeioex
Copy link
Contributor

xeioex commented Nov 26, 2019

Since 0fa4360 (0.3.8), JSON.stringify() for externals is supported.

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

No branches or pull requests

3 participants