Skip to content

jsonschema: distinguish json.Number from strings in Equal - #85

Open
abhinavrastogi2627 wants to merge 1 commit into
google:mainfrom
abhinavrastogi2627:fix/number-string-equality
Open

abhinavrastogi2627 wants to merge 1 commit into
google:mainfrom
abhinavrastogi2627:fix/number-string-equality

Conversation

@abhinavrastogi2627

Copy link
Copy Markdown

Equal(json.Number("1"), "1") currently returns true because both values have reflect.String kind. Objects and arrays decoded with UseNumber() inherit the same incorrect number/string equality.

Keep json.Number distinct from JSON strings in the string-kind fallback. Checking the Go type also covers valid numbers whose exponents are too large for big.Rat conversion. The existing mathematical comparison for representable numbers remains unchanged.

Closes #82. This is limited to equality; it does not duplicate the instance-type classification work in #81 or schema decoding changes in #84.

Validation:

  • Added regressions fail before the fix and pass after it, in both operand orders.
  • Covers nested objects/arrays decoded with UseNumber, oversized exponents, equivalent numeric spellings, and exact integers above the float64 precision boundary.
  • go test ./... passes with Go 1.23.12 and 1.26.8; go test -race ./..., go build ./..., formatting, and git diff --check pass.
  • go vet ./... reports two existing unexported-field JSON-tag fixtures in util_test.go and infer_test.go. The same diagnostics occur on an unmodified archive of the base commit.

Signed-off-by: Abhinav Rastogi <abhinavrastogi9596@gmail.com>
@google-cla

google-cla Bot commented Oct 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Equal treats json.Number and matching JSON strings as equal

1 participant