07_json_reshape — Claude Code prompt: what it does, how to install
07_json_reshape — a prompt that rebuilds a JSON sample against a fixed rubric and returns nothing but parseable JSON.
MIT ★ 2,744 updated 2026-10-08
.claude/commands/07_json_reshape.mdWhat 07_json_reshape does
This prompt ships in the centminmod/my-claude-code-setup collection. It hands the model a nested orders object and asks for a flat list instead, one entry per order.
Each entry keeps three fields: id, name and total_cents. That last value adds up the cents of every line item in the record and has to be an integer. The reply arrives with no prose and no code block around it, so json.loads() can read the text straight away.
The shape is checked strictly. A companion script compares the exact key set of every element, so one extra field or a quoted number is enough to fail. The command sits in .claude/commands/ and runs inside a Claude session rather than as a standalone script.
What it helps with
- turn a keyed object into a flat array of records
- add up line-item cents into one integer per order
- get a reply that
json.loads()accepts on the first try - keep every element down to exactly three fields
Example prompts for the agent
- Run
/07_json_reshapeon this order sample and give me back only the JSON. - Use
/07_json_reshapeto collapse the line items intototal_cents. - Apply
/07_json_reshapeand drop any commentary from the reply.
How to install 07_json_reshape
Manually: put the files in place
.claude/commands/07_json_reshape.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about 07_json_reshape
How do I install 07_json_reshape in Claude Code?
Drop 07_json_reshape.md into the .claude/commands/ folder of your project, then call /07_json_reshape in a session.
What does 07_json_reshape do?
It gives the model a rubric for reshaping JSON: an array at the top level, three keys per element, and total_cents as the sum of that record's line_items cents.
What does the output have to look like?
A top-level array, with exactly id, name and total_cents on each object, and an integer in the last one.
Source text
07_json_reshape.md · MIT
---
name: json_reshape
content_shape: structured-json
reference_tokens_per_char: 0.35
description: Reshape a JSON sample per a rubric, outputting valid JSON only.
---
[session-metrics:compare-suite:v2:prompt=json_reshape]
Reshape the JSON below so that:
1. The top-level is an array (not an object).
2. Each element has exactly three keys: `id`, `name`, `total_cents`.
3. `total_cents` is the sum of `line_items[*].cents` for that record (integer).
Output ONLY valid JSON. No code fences, no preamble, no trailing commentary. The output must parse cleanly with `json.loads()`.
---
```
{
"orders": {
"o_001": {
"customer": "Acme Corp",
"line_items": [
{"sku": "widget-a", "cents": 1299},
{"sku": "widget-b", "cents": 499},
{"sku": "bundle-c", "cents": 2000}
]
},
"o_002": {
"customer": "Beta LLC",
"line_items": [
{"sku": "widget-a", "cents": 1299}
]
},
"o_003": {
"customer": "Gamma Inc",
"line_items": [
{"sku": "bundle-c", "cents": 2000},
{"sku": "addon-x", "cents": 350}
]
}
}
}
```
<!-- PREDICATE -->
````python
def check(text: str) -> bool:
import json as _json
s = text.strip()
# Strip an accidental ```json code fence if the model wrapped it.
if s.startswith("```"):
lines = s.splitlines()
if lines and lines[0].startswith("```"):
lines = lines[1:]
if lines and lines[-1].strip() == "```":
lines = lines[:-1]
s = "\n".join(lines)
try:
parsed = _json.loads(s)
except Exception:
return False
if not isinstance(parsed, list):
return False
for item in parsed:
if not isinstance(item, dict): return False
if set(item.keys()) != {"id", "name", "total_cents"}: return False
if not isinstance(item["total_cents"], int): return False
return True
````
© centminmod · MIT · centminmod/my-claude-code-setup