json 0.1.0

A JSON parsing and validation library.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

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.

Authors:
  • Tony Hudgins
Dependencies:
none
Versions:
0.3.0 2017-Dec-10
0.2.0 2017-May-17
0.1.0 2015-Dec-22
~master 2017-Dec-21
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 5 downloads this month

  • 223 downloads total

Score:
1.1
Short URL:
json.dub.pm