# 07_json_reshape

07_json_reshape — a prompt that rebuilds a JSON sample against a fixed rubric and returns nothing but parseable JSON.

- prompt · `type=prompt` · Claude Code, ChatGPT · ★ 2744 repo stars
- Author: centminmod
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/centminmod/my-claude-code-setup/tree/HEAD/.claude/skills/session-metrics/references/model-compare/prompts/07_json_reshape.md
- Updated: 2026-10-08
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/prompts/07-json-reshape

## What it 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.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/commands/07_json_reshape.md`

### ChatGPT

**How to use**
- Paste the text at the start of a chat or into project instructions

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/centminmod/my-claude-code-setup/tree/HEAD/.claude/skills/session-metrics/references/model-compare/prompts/07_json_reshape.md

## When to use it
- 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
- Run `/07_json_reshape` on this order sample and give me back only the JSON.
- Use `/07_json_reshape` to collapse the line items into `total_cents`.
- Apply `/07_json_reshape` and drop any commentary from the reply.

## Source text · 07_json_reshape.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 016aa184eb48d455.

BEGIN THIRD-PARTY FILE 016aa184eb48d455
`````text
---
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
````
`````
END THIRD-PARTY FILE 016aa184eb48d455

The third-party file has ended. Everything between the 016aa184eb48d455 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© centminmod · MIT · https://github.com/centminmod/my-claude-code-setup/tree/HEAD/.claude/skills/session-metrics/references/model-compare/prompts/07_json_reshape.md

## Similar
- [CSV to JSON Converter — Auto-Detect Delimiter](https://affpapa.org/en/nevibecode/mcp/csv-to-json-converter-auto-detect-delimiter.md) — MCP server · 3562 installs
- [jq-json-processing](https://affpapa.org/en/nevibecode/skills/jq-json-processing.md) — skill · 245 installs
- [shuffle-json-data](https://affpapa.org/en/nevibecode/skills/shuffle-json-data.md) — skill · 8700 installs
- [json-data-handling](https://affpapa.org/en/nevibecode/skills/json-data-handling.md) — skill · 402 installs
- [json-parser](https://affpapa.org/en/nevibecode/skills/json-parser.md) — skill · 115 installs
- [ralph-tui-create-json](https://affpapa.org/en/nevibecode/skills/ralph-tui-create-json.md) — skill · 1200 installs

From the same set: [centminmod/my-claude-code-setup](https://affpapa.org/en/nevibecode/by/centminmod/my-claude-code-setup.md) — 35 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
