Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anowell/static-json-pointer
Rust macro to extract literals and tokens from JSON at compile time
https://github.com/anowell/static-json-pointer
Last synced: about 2 months ago
JSON representation
Rust macro to extract literals and tokens from JSON at compile time
- Host: GitHub
- URL: https://github.com/anowell/static-json-pointer
- Owner: anowell
- License: mit
- Created: 2018-04-11T06:22:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T06:33:11.000Z (over 6 years ago)
- Last Synced: 2024-11-17T14:49:14.766Z (about 2 months ago)
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## static-json-pointer
Macro to extract Rust tokens and literals from a JSON schema
If you have a file `schema.json`:
```json
{
"person": {
"name": {
"type": "String",
"value": "Zazu"
},
"age": {
"type": "Option",
"value": 42
}
}
}
```You can use a JSON pointer to specify the field for extracting a token or literal from JSON at compile time:
```rust
#![feature(proc_macro)]
extern crate static_json_pointer;
use static_json_pointer::json_token;// let name = String::from("Zazu");
let name = json_token!("schema.json", "/person/name/type")::from(json_literal!("schema.json", "/person/name/value"));// let age = Option::from(42);
let age = json_token!("schema.json", "/person/age/type")::from(json_literal!("schema.json", "/person/age/value"));assert_eq!(name, "Zazu".to_string());
assert_eq!(age, Some(42));
```The deserialized JSON is cached during build to prevent redundant reading and parsing during build.