-
Notifications
You must be signed in to change notification settings - Fork 13
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
coercing parse
#7
Comments
In my experience with REST APIs, often there is "Validate and Serialize" step in JSON request processing, Your approach is to construct object from json using information about class slot definition. Also approach with serializer as a separate object can do more smart conversions to user-defined types. In my opinion, getting validation and serialization right is a difficult topic, personally I would suggest I will also refresh my knowledge of validator and serializer libraries in CL and write here my thoughts about them. |
Thank you for the feedback, it's really appreciated. As somebody who uses C# regularly, I've become very attached/biased to how Newtonsoft JSON in particular goes about doing things, and ultimately with jzon I am looking to replicate the same general decisions made there. While I understand the dangers of doing all sorts of automagic coercion, it is as you said, very handy and applicable for many purposes when you "own" the incoming JSON or can otherwise trust it. Couple that with a JSON schema and you get a good enough safety for most uses where you don't get sent malicious JSON. That all said, you may be right for a v1 without it but my only trouble with that is: Am I offering enough different from all the other JSON libraries in CL right now? Because I don't really think so. |
A common feature in JSON parsers is automatic object mapping into language data types such as structures, classes, etc.
While not everyone (myself included) likes automatic conversions like this, it is without question incredibly useful & convenient when developing & doing exploratory programming.
For example, consider the following:
An alternative approach is to offer object coercion post-parse on the returned
hash-table
. And yet a third approach is to provide both options: allow a:type
option toparse
, but also export acoerce-value
or equivalent function that users can use on say, a hash table.Given the following JSON
from Bing Maps API
This allows the following:
where we don't need to coerce parse the full object hierarchy, just the deeply nested
elevation-data
objectThe text was updated successfully, but these errors were encountered: