WJP - Wizards JSON Parser
A library to parse raw Strings into workable types and vice versa.
Documentation:
Basic Usage:
Import the library into your Cargo.toml
[]
= "1.1.3"
// Example Struct to show how this library works
// Implementing the Serialize Trait allows you to call the .json() method on your struct
// Implementing the TryFrom<Values> Trait allows you to deserialize a JSON String into your struct
Output of the Example above:
{"opt":null,"code":123,"messages":["Important","Message"]}
Ok(Example { code: 123.0, messages: ["Important", "Message"], opt: None })
Explanation:
JSON is a lightweight, text-based, language-independent syntax for defining data interchange formats. Despite being language independent. It is not really optimised for the Rust language.
Example Json:
Key Value Pairs can have different positions every time:
This is currently also the case for this library because the Struct implementation uses a HashMap that allocates Key-Value Pairs every time at a new place and delivers them at different positions
Key Value pairs can just not exist, have the value null or be a different type:
This is supported, but it makes the parsing part more difficult and is the Reason why
the User of this library needs to implement From<Values>
and Serialize
for each of
their Structs they want to parse
JSON supports the IEEE 754 Standard for storing numbers:
This is supported, but just uses the f64::from_str()
underneath which should support all these cases
JSON also supports the UTF-8 Encoding
This library doesn't support \u escaped characters and doesn't advise on using escaped chars at all
JSON also supports different types inside of Arrays
This is supported, but the User needs to find out what to do with
the Vec<Values>
that can contain different types