pub fn from_json(
json: &[u8],
plan: &ExecutionPlan,
) -> Result<HashMap<String, LiteralValue>, LemmaError>Expand description
Convert JSON values to typed Lemma values using the ExecutionPlan for type information.
This function converts JSON values to Lemma types with the following rules:
| Lemma Type | Valid JSON Types | Conversion |
|---|---|---|
| Text | any | Strings pass through; numbers/booleans/arrays/objects serialize to JSON string |
| Number | number, string | Numbers pass through; strings are parsed as decimals |
| Boolean | boolean, string | Booleans pass through; strings parsed as “true”/“false”/“yes”/“no”/“accept”/“reject” |
| Percent | number, string | Numbers become percent; strings parsed (with or without %) |
| Date | string | ISO format “2024-01-15” or “2024-01-15T14:30:00Z” |
| Regex | string | Pattern string, optionally wrapped in /slashes/ |
| Unit types | string | Format: “100 kilogram”, “5 meter”, etc. |
Special handling:
nullvalues are skipped (treated as if the fact was not provided)- Unknown facts return an error
- Unparseable values return an error with a descriptive message