Skip to content

Accept JSON-array profiles, not just object streams#10

Merged
chenchaoyi merged 1 commit into
masterfrom
claude/profile-json-array
Jun 24, 2026
Merged

Accept JSON-array profiles, not just object streams#10
chenchaoyi merged 1 commit into
masterfrom
claude/profile-json-array

Conversation

@chenchaoyi

Copy link
Copy Markdown
Owner

What

Using hammer as an agent surfaced one clear "used it wrong" footgun: the
profile loader only accepted a bare stream of concatenated JSON Call
objects
. The obvious shape an agent emits for "a list of weighted calls" is
a JSON array — and that failed:

$ echo '[{"method":"GET","url":"http://x/ok","weight":3}]' | hammer -profile - ...
Error: load profile: json: cannot unmarshal array into Go value of type profile.Call

The README even had to caveat the format with "(no enclosing array — just
concatenate them)"
, a tell that everyone reaches for the array first.

Change

profile.LoadFromReader now peeks the first JSON token and accepts either
form interchangeably:

  • JSON array: [ {…}, {…} ] (now the documented primary shape)
  • legacy object stream: {…} {…} (still works, unchanged)

LoadFromFile inherits this for free. JSON field names stay case-insensitive,
so the lowercase keys agents tend to emit (weight, url, method) load too.

Tests

New cases: array form, single-element array, lowercase keys, empty array (→
no calls), malformed/truncated array, and the file path. All existing stream
tests stay green. go test -race ./..., go vet, and gofmt all clean.

Verified end-to-end against a local server — the previously-failing array
invocation now runs and reports per-status-code counts correctly.

🤖 Generated with Claude Code

A profile was only loadable as a bare stream of concatenated JSON Call
objects. An agent (or human) authoring a "list of weighted calls" reaches
for the obvious JSON array `[{...},{...}]` first, which failed with the
cryptic `cannot unmarshal array into Go value of type profile.Call`.

LoadFromReader now peeks the first JSON token and accepts either form
interchangeably: a top-level array or the legacy object stream. The file
loader inherits this for free. Field names remain case-insensitive, so the
lowercase keys agents tend to emit also load.

Docs updated to present the array as the primary shape; tests cover the
array, single-element array, lowercase keys, empty array, malformed array,
and the file path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chenchaoyi chenchaoyi merged commit 0b1673c into master Jun 24, 2026
1 check passed
@chenchaoyi chenchaoyi deleted the claude/profile-json-array branch June 24, 2026 08:01
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