Skip to content

Validation playground ​

Edit the story below. validateStory runs on every keystroke and reports each problem with a JSON Pointer to the field that caused it.

The story starts out broken on purpose. Try fixing it: correct the typo in goto, rename the duplicate id, make at positive, move the hotspot inside the frame, and give the polygon at least three points.

5 problems found

  • /scenes/intro/events/0/atinvalid_valueExpected a finite, non-negative time in seconds.
  • /scenes/intro/events/0/options/0/gotomissing_sceneScene "forst" does not exist.
  • /scenes/intro/events/1/idduplicate_idDuplicate ID "path".
  • /scenes/intro/events/1/areainvalid_valuex + width must not exceed 1.
  • /scenes/intro/events/2/pointsmissing_geometryThe resolved polygon shape requires points.

Code ​

ts
import { validateStory } from "@ivkit/core";

const result = validateStory(JSON.parse(text));

if (result.valid) {
  player.story = result.story;
} else {
  for (const { path, code, message } of result.errors) {
    console.error(`${path} (${code}): ${message}`);
  }
}

See Validating stories for every error code.