Crates.io | json5_nodes |
lib.rs | json5_nodes |
version | 2.0.1 |
source | src |
created_at | 2021-11-27 00:47:49.946064 |
updated_at | 2022-03-06 00:55:58.55235 |
description | Parse JSON5 into nodes that retain both JSON value and input file location |
homepage | |
repository | https://github.com/jlyonsmith/json5-nodes |
max_upload_size | |
id | 488208 |
size | 25,257 |
This Rust library parses JSON5 into JsonNode
structures that contain both the JSON value and the location of the data in the original string. This allows you to use JSON5 as a configuration format and refer back to the location of semantic errors in the original JSON5 as opposed to just reporting syntactic errors when reading the file.
See the stampver-rs
tool for an example of how to use the library.
We use IndexHashMap
instead of a plain HashMap
because JavaScript mostly preserves the order of insertion into objects. This libraries JSON5 parser currently only allows string based keys, so the rules are simplified.
All JSON breaks down into nodes of different types, JsonNode::Null
, JsonNode::String
, JsonNode::Bool
, JsonNode::Integer
, JsonNode::Float
, JsonNode::Array
and JsonNode::Object
. We define and parse two types of numbers because it's more important in statically typed languages to specifically pick one or the other.
This library is a work in progress. The following are some things that still need to be done:
Err
cases; the values are already parsed to be valid input.parse
can be written back out in stringify
with full fidelity. In particular escape codes are not handled at all and hex numbers don't round-trip.