-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
a method to serialize object.Object into a JSON compatible struct #173
Comments
I think the general case is pretty hard, because I can imagine a script which ended:
That's not something you can return as json unless you changed it to:
That said I think the hash object is a good exception. I could add a JSON interface to allow hashes, specifically, to be converted to json. So your example would work. (I guess similarly an array-object could be made to work, providing all the members had the same type. So Would hash-only suffice for your use-case? |
Yes, hash only would work. I think that is a reasonable expectation to be fair to your point as well. |
Hrm, now I say that of course So I can implement for:
That'd probably suffice for most cases. |
Thats true. Good point. How do you see one serializing the return object of the eval filter as JSON? |
I would probably say you'd write something like this:
At which point |
That LGTM. How difficult is something like that to implement? |
I don't think it would take too long - I'd just need to define the interface and then add the Handling the case of recursion / hashes will be harder than the string/bool/integers, but even so I think a couple of hours should suffice. I'll have a stab at it tomorrow/Monday. |
I accidentally clicked the wrong emoji.. haha -- sounds good. Thanks for your effort. |
PR in-progress:
TODO
Will come back to it later in the day. |
Needs more testing/experimentation, but I think it is complete now. |
I'll pull it in and give it a shot. Thanks for knocking it out. |
With eval.Execute returning the actual object.Object, it would be very useful to have a way to convert the object.Object into a struct that can be serialized as JSON.
A simple eval script can then be used to create JSON views by plucking the data from the object, and returning a different view of the data, like in this sample script:
Even though my actual object contains significantly more data, in this particular case, it'd only be a JSON object that returns a first name and a city.
The text was updated successfully, but these errors were encountered: