agentleFS
0xelitesystem0xelitesystem/claude-skills-collection/skills/json-schema-from-sample/SKILL.md

json-schema-from-sample

Skill0 starsChanged 5 months agoMITView on GitHub

Use when the user wants to generate a JSON Schema from one or more sample JSON documents. Triggers on "create a schema for this", "generate JSON Schema", "validate this shape", "infer types from this JSON", or when the user pastes JSON and asks how to validate similar documents.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 3 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Confirm schema draft version: Default to Draft 2020-12. Common alternatives:

    line 14
  2. Very specific:

    Types per field: If a field is sometimes a string and sometimes null, type is ["string", "null"].

    line 19
  3. Distinctive:

    Required fields: Only fields present in ALL samples are required.

    line 20
  4. Distinctive:

    Enums: If a field has a small set (≤10) of distinct string values across all samples, suggest making it an enum.

    line 21
  5. Very specific:

    Patterns: If string values match a clear pattern (UUID, email, ISO date, semver), use the standard format keyword (uuid, email, date-time) …

    line 22
  6. Very specific:

    Number ranges: Use minimum/maximum only if the samples suggest a meaningful bound (e.g.

    line 23
  7. Very specific:

    Array item type: If an array always contains the same shape, use that as items.

    line 24
  8. Very specific:

    Output the schema with comments explaining choices: Use description fields liberally.

    line 27
  9. Very specific:

    MUST NOT: add "additionalProperties": false by default.

    line 42
  10. Very specific:

    MUST NOT: use "format": "X" for non-standard formats.

    line 44
  11. Very specific:

    If samples are large or the schema is going into a project, ask whether to write to a file (schema.json) or just paste inline.

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

JSON Schema from Sample

Generate a JSON Schema (Draft 2020-12 by default) from sample documents.

Process

  1. Get samples. Ideally multiple. One sample produces a schema that's too tight (every field is required, every enum has one value). Ask for 2-5 samples that represent the variation you expect to see.
  2. Confirm schema draft version. Default to Draft 2020-12. Common alternatives:
    • Draft 7: still widely used, supported by older tooling
    • Draft 4: legacy, only if explicitly required
  3. Walk the samples to infer:
    • Types per field. If a field is sometimes a string and sometimes null, type is ["string", "null"]. If sometimes string sometimes number, that's worth flagging to the user as likely a bug.
    • Required fields. Only fields present in ALL samples are required. Mention which fields varied so the user can decide if the variation is real or coincidental.
    • Enums. If a field has a small set (≤10) of distinct string values across all samples, suggest making it an enum. Ask before committing, the samples may not have exhausted the values.
    • Patterns. If string values match a clear pattern (UUID, email, ISO date, semver), use the standard format keyword (uuid, email, date-time) or a pattern regex. Don't over-fit.
    • Number ranges. Use minimum/maximum only if the samples suggest a meaningful bound (e.g. age 0-120). Don't add bounds based on coincidental sample values.
    • Array item type. If an array always contains the same shape, use that as items. If items are mixed, use prefixItems or oneOf.
    • Nested objects. Recurse with the same logic.
  4. Output the schema with comments explaining choices. Use description fields liberally. JSON Schema doesn't allow // comments, so put rationale in description.
  5. Below the schema, write a short audit:
Audit:
- 12 fields total
- 8 required, 4 optional (only present in some samples)
- 2 enum candidates: status, priority, confirm complete list
- 1 type ambiguity: user_id is sometimes string, sometimes integer (likely a bug?)
- 0 format guesses below 80% confidence

What NOT to do

  • MUST NOT add "additionalProperties": false by default. It locks down the schema and breaks forward compatibility. Add it only if the user asks.
  • MUST NOT infer regex patterns from a single sample value. Patterns need at least 3 examples.
  • MUST NOT use "format": "X" for non-standard formats. Only the spec-defined formats: date-time, date, time, email, uuid, uri, ipv4, ipv6, hostname. For others, use pattern.
  • MUST NOT silently drop fields that appear in only one sample. Make them optional and report which ones.

Common pitfalls to call out to the user

  • "All samples have a positive count. I made minimum: 0. Is count ever negative?"
  • "Samples never have null values. Should null be allowed for any field?"
  • "Field id is integer in some samples, string in others. This is usually a bug. Which is correct?"

Output destinations

If samples are large or the schema is going into a project, ask whether to write to a file (schema.json) or just paste inline. Default to inline for ≤100 lines, file for larger.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.