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.
Task: Extract data to JSON · Other tasks
Fill in the details
Paste the text itself. Several records are fine; Claude will return one object per record if your field list says so.
List each field with its type or format. You can also paste an example JSON object or a JSON Schema.
Copy your prompt
This site doesn't run Claude or show model output. Results depend on your input and the model you use.
You've edited the prompt, so changes to the fields aren't applied.
What you type is kept in this tab's session storage so a reload doesn't lose it. Use "Clear this task" to remove it. Browsers can restore session data when they reopen tabs, so closing a tab isn't a guaranteed way to erase it.
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: Turn a long document into a faithful summary: main point first, key points by importance, then decisions and open questions.
- 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 (Anthropic documentation)
- Prompting best practices: Structure prompts with XML tags (Anthropic documentation)
- Prompting best practices: Long context prompting (Anthropic documentation)