D-Programming-Language/phobos — pull request #1421 by Dav1dde (2013-07-19 12:53:47+00:00)
Title: Improved std.json api, typesafe and easier to use

The ´std.json` API was a not typesafe at all and lacked a useable API, this is an attempt to make the API typesafe (Exception instead of a more or less random Segfault) and more useable, but don't break backwards compatability.

This pull-request adds:

* Typechecks for `str`, `integer`, `object` etc. (using old API)
* "real" typechecks for `opIndex` overloads
* `foreach` overloads for arrays and objects
* `toString` for JSONValue, allowing `json.to!string`
* `opAssign` and a proper constructor (see example below)

```D
auto payload = [
"accessToken" : JSONValue("Token"),
"clientToken" : JSONValue(3),

"selectedProfile" : JSONValue([
"id" : "A77FF703C",
"name" : "My Name is David"
])
];

auto json = JSONValue(payload).to!string;
```

Another example, the [unittest].(https://github.com/Dav1dde/phobos/blob/31f66db24881a02ca5a00a14333659e6ad88114a/std/json.d#L718-L767)

I tried to extend the API without introducing new functions which don't "logically" extend the current design, to make it an easy decision to merge this pull.