NodeFox

Lesson 5 · Intermediate

Validate JSON before using it

Turn a model or API result into a small, explicit data contract.

1:43 video guide + written guide

Source-based instructional visualization · synthetic examples · AI narration. This explains configuration and behavior; it is not a recording of a verified live run.

Jump to a chapter

Before you start

A signed-in NodeFox workspace. Use synthetic data and prepare outputs before enabling external writes.

  1. 01Name the contract

    For a purchase-order check, use quantity, orderUnitCents and contractUnitCents. Keep money in integer cents. Include a source reference separately so a reviewer can verify where each value came from.

  2. 02Validate at the boundary

    A structured model response still needs validation. Check that required fields exist, numbers are finite, quantities are positive and currency is known. Reject or route incomplete values for review rather than silently substituting zero.

  3. 03Pass only useful fields

    Have Code emit a compact object with validated inputs, the calculated difference and a reviewRequired flag. Keep the original source accessible. Downstream steps should not parse a paragraph to recover a price.

  4. 04Inspect both paths

    Test a valid example and a missing quantity. The valid record should produce a calculated result; the malformed input must not reach an external Writer. Schemas describe structure but do not establish that a source claim is true.

Example configuration or input

{"quantity":20,"orderUnitCents":9500,"contractUnitCents":9800}

Expected result

differenceCents: 6000; reviewRequired: true.

If the result is wrong

If a value is a string, decide whether to explicitly parse it or reject it. Do not rely on JavaScript coercion for financial checks.