Description

A JSON parsing and validation library.

Package Information

Version0.1.0 (2015-Dec-22)
Homepagehttps://github.com/SirTony/json.d
Repositoryhttps://github.com/SirTony/json.d
LicenseMIT
CopyrightCopyright © 2015 Tony Hudgins
AuthorsTony Hudgins
Registered byTony J. Ellis
Dependenciesnone

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

What is it?

JSON.d is an alternative to phobos' (D's standard library) built-in JSON module that contains its own value type and its own parser that adheres to the JSON standard as specified at http://www.json.org/.

Why?

Phobos' JSON module leaves much to be desired; it can sometimes be tedious to work with and can overcomplicate the manipulation of even simple JSON objects. This is partly due to the inherent challenges associated with mapping an implicitly typed structure to a statically typed language, and partly due to phobos' implementation being more simplistic and not leveraging the full capabilities of the language.

JSON.d aims to provide an implementation that's as easy as possible to work with, making it feel as natural as possible to read and manipulation JSON documents.

Features

JSON.d is still young, and as such it is prerelease software, so please keep in mind functionality is limited for now and it is not bug-free.

  • [x] Parsing JSON string to object structure.
  • [x] Writing object structure back to JSON.

Planned Features

  • [ ] Validating JSON documents against schemas
  • [ ] Validating JSON documents against a custom, TypeScript inspired DSL.
  • [ ] Generating valid schemas from the DSL.

Getting started

Through dub

JSON.d is available in the dub package repository.

Building from source

Since JSON.d uses dub, building from source on any platform is dead-simple.

First clone the repository:

$ git clone https://github.com/SirTony/json.d.git ./json.d

Then compile the library:

$ cd json.d
$ dub build --build=release

Compiled binaries will be located in the bin directory.

Example

// store.json
{
    "products": [
        {
            "id":    1,
            "name":  "Door hinge",
            "price": 0.75,
            "tags":  [ "home improvement", "hardware" ]
        },
        {
            "id":    2,
            "name":  "Box of screws",
            "price": 3.50,
            "tags":  [ "hardware", "tools" ]
        }
    ]
}
// store.d

import std.file;
import std.stdio;

import json.d;

void main()
{
    auto json = readText( "store.json" );
    auto store = json.parseJson();

    foreach( product; store["products"] )
        writefln( "%s: $%g", product["name"], product["price"] );
}

Things to note

JSON.d is tested on Windows with the DMD compiler, version 2.068. Other D compilers such as LDC, SDC, and GDC are not officially supported, but should still work.

Available versions

0.1.0 ~master