I'm writing a private library for a project I'm working on. I can stop there. No big deal; but I figured I should ask if the rest of the community is interested.
The library adds field name annotation for standard objects for conversion to JSON (%* in std/json to JsonNode) or JSON text (std/marshal).
For example, instead of this:
import
std/marshal
type Widget = object
name: string
`type`: string # have to place backtics
kind: string # confusing at best
var x = Widget(name: "bearing")
x.`type` = "steel"
x.kind = "smoothness-4"
var doc = $$x
writeFile("bearing.json", doc)
I can instead do this:
import
something
type Widget = object
name: string
typ {.jsonField("type").}: string
widgetKind {.jsonField("kind").}: string
var x = Widget(name: "bearing")
x.typ = "steel"
x.widgetKind = "smoothness-4"
var doc = $$x
writeFile("bearing.json", doc)
And get the same bearing.json file.
If there is interest, I could package it up and place it in nimble.directory. I would NOT reinvent json/std so that this library is still compatible with other libraries that use json/std. I could also do a nim-RFC and offer a PR to json & marshal; but that is probably a long shot.