Shall I use std.json at my own risks ?

Rob T alanb at ucora.com
Tue Nov 12 22:15:56 PST 2013


On Wednesday, 13 November 2013 at 05:26:54 UTC, jean christophe 
wrote:
>
> Hello
>
> would you guys say that std.json is a good or bad choice dor a 
> desktop application ? I've read many threads about it on the 
> forum and finally I don't realy know what to do Oo`
>
> I need my Gtkd application to maintain a (possibly big) archive 
> database of financial records downloaded daily from the server 
> application. In my case JSON seems to be the most convenient 
> format. Please let me know if, according to you, std.json will 
> cast aside as std.xml.
>
> Thenks.
>
> PS: As I'm new to the forum, I'd like to thank the D core 
> community for such a GREAT language. I shall admit that it was 
> difficult to abandon Emacs :s Anyway I've not been so 
> positively impressed by a new language since Java 0.

I've been using it std.json extensively. I don't really like it 
because traversing the structure is not so fun, but it's very 
fast and has been very reliable.

Whether or not json is the right choice for your application is 
something only you can decide. I know for example that json is a 
poor choice for human readable things such as configuration files 
because the format is ugly and comments are not allowed, also if 
your application must preserve order among fields, forget about 
json, order is only preserved among array elements.

json also suffers from data typing issues because the type must 
be inferred from the supplied data. For the most part it's OK, 
but care must be taken to ensure the right conversions will take 
place, for example if you want the number 1 to be seen as a real 
number, it must be specified as 1.0.

Finally, json is a subset of java script, and if you are 
interfacing with a JS application, it turns out that JS has no 
integer types, only real types which are of a lower resolution 
than what D can provide, this means that you have to take care 
not to overflow integers past a maximum value where precision is 
lost. You will not get an error, instead your numbers will lose 
some of their less significant digits - it's an insidious problem 
if not dealt with at the source ends.

I guess that I'm saying is that while std.json is rock solid and 
very fast, you may want to consider better alternatives to the 
json format unless there's a technical reason why json must be 
used.

Have fun :)

--rt


More information about the Digitalmars-d mailing list