treeform / jsony

A loose, direct to object json parser with hooks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some comments

StefanSalewski opened this issue · comments

Dear Sir,

I can confirm that your jsony module compiles and works with latest devel compiler, at least the most important procs toJson() and fromJson(). It was easy to replace std/json with that.

The fact that extra json fields are ignored and missing json fields keep their default values, is very important for real life development, and most other json libs ignore that. Actually I had stopped the development of my CAD/EDA tool for a long time, due to the fact that each tiny modification of data structures invalidates all stored test datasets. So after switching to your tool, I may get again some more motivation to do at least some work on that project again.

I also tried nim-jaml recently, but it has some issues: flyx/NimYAML#130
And json from status-im has some interesting issues as well, at least with latest devel compiler.

For your jsony, I would like to have a pretty option. Std/json has a pretty proc, and status-im provides a pretty flag. That is very useful, as in CAD area, users may like to edit data files manually with an text editor.

For default values, Nim 2.0 allows to specify default values for object fields. It would be nice if that default would be used as well. Your hooks work fine as well, but documentation is not fully clear about the fact that only binary zero default is used actually. From Readme: "... missing json fields keep their default values."

type
  Line = object
    x1, y1, x2: float
    pi: float = 3.14159


proc newHook(line: var Line) =
  # Populates the object before its fully deserialized.
  line.pi = 3.14159

I hope we will get support for "Pretty and "Easy way to skip fields of an object" #50 soon, would be really useful.

Best regards,

Dr. Stefan Salewski

Yeah as Nim grows so should jsony. I have a branch where I started to add jsony pretty support. I also want to add https://json5.org/ standard as a "pretty" reader.