Skip to content

Add JSONValue type, helpers, and usage example#25

Merged
WendellXY merged 4 commits intomainfrom
wendell/add-json-value
Mar 24, 2026
Merged

Add JSONValue type, helpers, and usage example#25
WendellXY merged 4 commits intomainfrom
wendell/add-json-value

Conversation

@WendellXY
Copy link
Copy Markdown
Owner

This pull request introduces a new dynamic JSON value type, JSONValue, to the codebase. JSONValue allows for flexible, schema-less representation and traversal of arbitrary JSON data, similar to Rust's serde_json::Value. The implementation includes decoding/encoding support, runtime accessors, path-based traversal, and literal conveniences. Comprehensive tests and documentation are also added.

New dynamic JSON value support:

  • Added the JSONValue enum to represent any JSON value (null, bool, string, int, double, array, object) with full Codable conformance, runtime accessors, and literal initializers. Includes path-based traversal via the new JSONPathComponent type, and convenience methods for encoding/decoding from JSON data and strings. (Sources/CodableKit/JSONValue.swift)
  • Introduced detailed documentation and usage examples for JSONValue in the project README, demonstrating decoding, traversal, and construction from JSON strings and literals. (README.md)

Testing:

  • Added a comprehensive test suite for JSONValue, covering decoding, encoding, round-tripping, runtime accessors, path traversal, literal construction, and integration with Codable models. (Tests/CodableKitTests/JSONValueTests.swift)

@WendellXY WendellXY self-assigned this Mar 24, 2026
Copilot AI review requested due to automatic review settings March 24, 2026 14:12
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b69cbee48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +244 to +245
} else if let value = try? container.decode(Double.self) {
self = .double(value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve out-of-range JSON numbers losslessly

In JSONValue.init(from:), values that fail Int decoding are immediately decoded as Double, which silently rounds many valid JSON numbers (for example, integers larger than Int.max such as 9223372036854775809). This means decoding and then re-encoding can change the numeric value, so arbitrary JSON payloads are no longer lossless. Because this type is intended for schema-less JSON transport, numeric corruption here is user-visible and should be avoided by using a lossless number representation (e.g., Decimal/string-backed number case) before falling back to binary floating point.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a dynamic JSONValue type to CodableKit to support schema-less JSON decoding/encoding, runtime inspection, and path-based traversal, along with README usage examples and a dedicated test suite.

Changes:

  • Introduces JSONValue, JSONValueError, and JSONPathComponent with Codable conformance, literal initializers, accessors, and traversal helpers.
  • Adds runtime tests covering decoding/encoding, accessors, path traversal, and convenience JSON string/data APIs.
  • Updates the README with a “Dynamic JSON values” usage example.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Sources/CodableKit/JSONValue.swift Implements the JSONValue dynamic JSON representation and helper APIs.
Tests/CodableKitTests/JSONValueTests.swift Adds Swift Testing-based coverage for JSONValue behavior and conveniences.
README.md Documents basic usage patterns for decoding and traversing JSONValue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@WendellXY WendellXY merged commit 41a5dcb into main Mar 24, 2026
8 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.

2 participants