hjson-d 0.2.0
Hjson parser compatible with std.json and ASDF.
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:
This package provides sub packages which can be used individually:
hjson-d:asdf - ASDF interop for hjson-d.
hjson-d
Hjson-d is a Hjson parser written in D. Hjson is a syntax extension to JSON, designed to be easier for humans to work with. It improves readability and helps avoid bugs caused by missing/trailing commas:
// example.hjson
{
"name": "Hjson",
"readable": {
omitQuotes: This is a quoteless string
omitCommas: [
1
2
3
]
trailingCommas: {
a : true,
b : false,
c : null,
}
multilineStrings:
'''
Lorem
ipsum
'''
# Comments
// C-style comments
/*
Block
comments
*/
}
}
Getting started
Add hjson-d to your DUB project:
dub add hjson-d
Features
Simple parsing
Hjson strings can be parsed using the parseHjson
method:
import std.json : JSONValue;
import std.file : readText;
import hjson;
JSONValue value = readText("example.hjson").parseHjson;
When parseHjson
encounters invalid input, it will throw a HjsonException
describing the error.
ASDF interop
Add hjson-d:asdf
to your DUB project to allow parsing Hjson directly into ASDF representation:
dub add hjson:asdf
All you have to do is call parseHjsonToAsdf
:
import asdf.asdf : Asdf;
import std.file : readText;
import hjson.asdf;
Asdf asdf = readText("example.hjson").parseHjsonToAsdf;
Limitations
- Emitting Hjson is not supported.
parseHjson
only reads a single Hjson value and will not attempt to look further in the input to find errors. Because of that certain errors will not be detected:
[1, 2, 3, 4] 5 #Trailing 5 will not cause an error because parsing stops after [1, 2, 3, 4]
- Parsing from arbitrary forward ranges is currently not supported, but is planned for the future.
Bugs
- Omitting braces for root object is not supported.
- 0.2.0 released 4 years ago
- k2aj/hjson-d
- MIT
- Copyright © 2020, Krzysztof Jajeśnica
- Authors:
- Sub packages:
- hjson-d:asdf
- Dependencies:
- none
- Versions:
-
0.2.0 2020-Sep-14 0.1.0 2020-Sep-12 ~master 2020-Sep-14 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
9 downloads total
-
- Score:
- 0.3
- Short URL:
- hjson-d.dub.pm