Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jlyonsmith/json5-nodes
Parse JSON5 into an AST with line/column information.
https://github.com/jlyonsmith/json5-nodes
Last synced: 6 days ago
JSON representation
Parse JSON5 into an AST with line/column information.
- Host: GitHub
- URL: https://github.com/jlyonsmith/json5-nodes
- Owner: jlyonsmith
- License: unlicense
- Created: 2021-11-22T23:33:27.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-06T00:55:45.000Z (over 2 years ago)
- Last Synced: 2024-08-09T07:10:04.486Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 34.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json5_nodes
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`](https://github.com/jlyonsmith/stampver-rs) tool for an example of how to use the library.
## Implementation
We use [`IndexHashMap`](https://crates.io/crates/hashlink) instead of a plain [`HashMap`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) because JavaScript [mostly preserves the order of insertion into objects](https://stackoverflow.com/a/38218582). 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.
## To Do
This library is a work in progress. The following are some things that still need to be done:
- [ ] Get closer to 100% code coverage with the unit tests.
- [ ] Rewrite the hex conversions to avoid the pathological `Err` cases; the values are already parsed to be valid input.
- [ ] Maybe ensure that what's read by `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.
- [ ] A better README!