from_json

Function from_json 

Source
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 TypeValid JSON TypesConversion
TextanyStrings pass through; numbers/booleans/arrays/objects serialize to JSON string
Numbernumber, stringNumbers pass through; strings are parsed as decimals
Booleanboolean, stringBooleans pass through; strings parsed as “true”/“false”/“yes”/“no”/“accept”/“reject”
Percentnumber, stringNumbers become percent; strings parsed (with or without %)
DatestringISO format “2024-01-15” or “2024-01-15T14:30:00Z”
RegexstringPattern string, optionally wrapped in /slashes/
Unit typesstringFormat: “100 kilogram”, “5 meter”, etc.

Special handling:

  • null values are skipped (treated as if the fact was not provided)
  • Unknown facts return an error
  • Unparseable values return an error with a descriptive message