3 ms·
I often do something similar when documenting a structure as a first pass.. { "name": String, // [required] "age": Number, //int "groups"
by tracker1 11y ago
I often do something similar when documenting a structure as a first pass..
{
"name": String, // [required]
"age": Number, //int
"groups": [String], // groupId (UUID)
...
}
The structure represents the actual object, and comments allow for additional context/details... it's worked pretty well for documenting APIs that are under development, or intention when working with other devs.
- willvarfar 11y agoYes and with obiwan you can pass that structure to data = json.loads(tainted, template=your_spec) And that will throw an exception if the JSON didn't match the template. From then on its just to safely use the JSON you just loaded, knowing it is well formed and matches the expected shape... :)
- GauntletWizard 11y agoAt that point, you're inches from specifying protobufs or thrift, and the advantages in structured object parsing and tooling that exists from using one of those ecosystems is not to be ignored.
- willvarfar 11y agoJSON is widely used for interchange. Often JSON is a requirement, not a choice.
- tracker1 11y agoIt's worth noting that depending on the language, JSON parsing is faster than binary implementations. Also worth noting that you can do JSON + gzip if there are larger records to be transferred regularly.