# Extract data to JSON

Pull specific fields out of messy text into JSON that matches your field list, with clear rules for missing or ambiguous values.

Paste into: **a new Claude conversation**

## Prompt template

How the builder on the page fills in this template, so you can do the same:

- `{{key}}` becomes the text entered for that field, exactly as typed. Empty text, or text that is only whitespace (spaces, tabs or line breaks), counts as empty: a required field then becomes `[fill in: <label>]` with its label, and an optional field becomes nothing.
- For a choice field, `{{key}}` becomes the text of the chosen option, or of the default when none is chosen.
- Text between `{{#key}}` and `{{/key}}` stays only when that field is not empty; a choice field always counts as filled. The markers themselves are removed, and a marker that stands alone on its line takes its line break with it.
- Each value is inserted once, as it is: `{{…}}` inside a value stays as typed.

````text
<source>
{{source}}
</source>

Extract data from the source above into JSON.

Fields to extract:
{{schema}}

Rules:
- Use only information stated in the source. Do not infer, estimate or invent values.
- When a value is missing: {{missing}}.
- Keep names, numbers and dates as written unless the field list asks for a specific format.
- If the source contains several records, return a JSON array with one object per record.

Return the JSON first, inside a fenced ```json code block. After the code block, add a short list of anything that was ambiguous or that you could not find, with the text it came from. If nothing was ambiguous, say so.
````

## Fields

- `{{source}}` (required): Source text. Paste the text itself. Several records are fine; Claude will return one object per record if your field list says so.
- `{{schema}}` (required): Fields to extract. List each field with its type or format. You can also paste an example JSON object or a JSON Schema.
- `{{missing}}`: When a value is missing. Choose one:
  - Set it to null (default)
  - Leave the field out

This site doesn't run Claude or show model output. Results depend on your input and the model you use.

## When to use this template

- You have unstructured text, such as emails, notes, listings or form replies, and need the same few fields from each item in a predictable format.
- You want output you can load into a spreadsheet, a script or a database without cleaning it up by hand.
- You need to know which values were missing or unclear, not just a best guess for each one.

## When not to use it

- The data is already in a table, CSV or spreadsheet. Converting it with a script or spreadsheet export is more reliable than a model.
- You need thousands of records copied with no errors at all. A prompt cannot ensure that; split the work into small batches you can verify, or use a parser if the format allows it.
- The values must be calculated or looked up, not read from the text. This template tells Claude to use only what is stated.

## Why this structure

- The source text sits inside `<source>` tags at the top, and the field list and rules come after it, which helps Claude tell the material apart from the instructions.
- You describe each field with its type or format, which leaves less room for guesswork about names, dates and numbers. A concrete field list is also how Anthropic's documentation suggests getting more consistent output.
- The missing-value rule is one explicit choice for all records rather than something decided per record. With "Set it to null" every object asks for the same keys; with "Leave the field out", objects can have different keys, which some tools handle better.
- Keeping the JSON in its own code block makes it easier to copy. Copy only the contents of that block, then validate the JSON before you import it.
- The closing list of ambiguous or missing values asks Claude to keep uncertainty visible instead of hiding it in plausible-looking data.

## Example input (fictional)

Source text:

```
Order 1042 from Juniper Lane Ceramics (fictional), placed 3 March 2026, 12 mugs at 9.50 each. Delivery address: Unit 4, Alder Court. Order 1043, placed 5 March, 2 teapots; price to be confirmed.
```

Fields to extract:

```
order_id (string), date (YYYY-MM-DD), item (string), quantity (number), unit_price (number)
```

When a value is missing:

```
Set it to null
```

## Follow-ups to send Claude

- Check every value in the JSON against the source and list any that are not stated word for word, with the closest matching text.
- Return the same data as CSV with a header row, using the same field order.
- Add a field called source_quote to each object containing the exact sentence each record came from.

## Common mistakes

- Describing fields vaguely, such as "the date". Say which date and in what format, for example "order date as YYYY-MM-DD".
- Pasting more records than you can check. Start with a small batch, verify it, then run larger batches with the same prompt.
- Treating the output as verified. A value can look right and still be wrong; the follow-up that checks values against the source helps catch this.

## Related templates

- [Summarize a document](https://awesomeclaudeprompts.com/prompts/summarize-document/): Turn a long document into a faithful summary: main point first, key points by importance, then decisions and open questions.
- [Analyze customer feedback](https://awesomeclaudeprompts.com/prompts/analyze-customer-feedback/): Group raw customer comments into themes, priorities or feature requests, with counts and quotes that show where each finding comes from.

## Sources

- [Increase output consistency](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/increase-consistency) (Anthropic documentation)
- [Prompting best practices: Structure prompts with XML tags](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#structure-prompts-with-xml-tags) (Anthropic documentation)
- [Prompting best practices: Long context prompting](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#long-context-prompting) (Anthropic documentation)

---

Awesome Claude Prompts is an independent project. It is not affiliated with, endorsed by, or sponsored by Anthropic. Claude is a trademark of Anthropic, PBC.
