Skip to content

Add --format json to structpad layout - #3

Merged
Gulliby merged 1 commit into
mainfrom
feature/layout-format-json
Oct 16, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/layout-format-json

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Before

structpad layout printed only a text table, so a script that wanted offsets, sizes or padding had to parse it.

After

structpad layout --format json (or --format=json) prints the same structs as one JSON array (two-space indent, LF, UTF-8) with name, size, align, padding, packed, fields and gaps. --format text is the default. Only layout takes the option; suggest and check refuse it, and invalid or missing values exit 2.

structpad layout --format json pair.sp

The full output for struct Pair { u8 a; u32 b; } is in the README.

How

  • src/structpad/render.py: new render_layout_json.
  • src/structpad/cli.py: the --format option and the usage line.
  • tests/test_format_json.py: 14 new tests; tests/test_cli.py: the usage constant only.
  • README.md: the new option documented.

145 tests pass (131 before) and ruff is clean.

@Gulliby
Gulliby merged commit f07de27 into main Oct 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant