Shall I use std.json at my own risks ?

Adam D. Ruppe destructionator at gmail.com
Wed Nov 13 06:39:05 PST 2013


std.json is ok. If you want a prettier api btw, I wrote a module 
called jsvar that uses it to provide a D type that is very 
similar to a javascript var:

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/jsvar.d

void main() {
	import arsd.jsvar;
	
	auto some_json = `{"foo":"bar","number":20}`;
	var a = var.fromJson(some_json);

	assert(a.foo == "bar"); // works for easy access
	assert(a.number == 20);

	a.number += 15; // you can modify it too

	import std.stdio;
	writeln(a.number); // 35
}

If you want the specific type, there's a.payloadType == 
var.Type.Integral and so on. Then you can do int b = a.get!int; 
(you can actually do that even if a is a string, it will try to 
convert for you)


I think std.json's core is usable, just the interface isn't as 
beautiful as it could be in D. My jsvar tries to close that gap.


More information about the Digitalmars-d mailing list