from_json

Function from_json 

Source
pub fn from_json(
    json: &[u8],
    doc: &LemmaDoc,
    all_docs: &HashMap<String, LemmaDoc>,
) -> Result<Vec<String>, LemmaError>
Expand description

Convert JSON fact overrides to Lemma syntax strings

Expected JSON formats:

  • Text: “string value”
  • Number: 123 or 45.67 as number, or “123” as string (parsed and passed through)
  • Percentage: 0.21 as number (becomes “21%”), or “21%” as string (passed through)
  • Boolean: true/false as boolean (becomes “true”/“false”), or “yes”/“no”/“accept”/etc as string (passed through)
  • Date: “2024-01-15” or “2024-01-15T14:30:00Z”
  • Regex: “pattern” or “/pattern/” (passed through as string)
  • Unit types: “100 kilogram” (Lemma syntax as string)

Example:

{
  "name": "John",
  "rate": 0.21,
  "active": true,
  "weight": "75 kilogram",
  "start_date": "2024-01-15"
}