Skip to content

Improve json conversion and stringify behavior#3210

Open
bobzhang wants to merge 1 commit intomainfrom
codex/improve-json-package-consistency-and-performance
Open

Improve json conversion and stringify behavior#3210
bobzhang wants to merge 1 commit intomainfrom
codex/improve-json-package-consistency-and-performance

Conversation

@bobzhang
Copy link
Contributor

@bobzhang bobzhang commented Feb 8, 2026

Motivation

  • Consolidate deprecated Json helpers into a dedicated module for API clarity and consistency.
  • Prevent surprising conversions by rejecting fractional numbers when decoding Int/UInt.
  • Fix stringify/escape behavior to avoid unwanted indentation/newlines and improve common-case performance for unescaped strings.
  • Add missing documentation for JsonPath helper APIs to improve discoverability.

Description

  • Moved legacy accessors (Json::as_*, Json::item, Json::value) out of the main module into json/deprecated.mbt and left deprecation hints in place.
  • Tightened from_json implementations for Int and UInt to reject fractional numbers by checking n == n.trunc() and added corresponding tests in json/from_json_test.mbt that assert fractional values fail with an expected integer error.
  • Adjusted Json::stringify to not emit a leading indent for objects until the first property is written and to avoid emitting a trailing indent for empty objects when a replacer filtered out members, fixing compact output when Replacer::keep([]) is used.
  • Added a fast-path to escape that returns the original string when no characters require escaping to avoid extra allocation/work in the common case.
  • Added brief doc comments for JsonPath and its add_index/add_key helpers and added a unit test verifying replacer + indentation behavior in json/json_test.mbt.

Testing

  • Ran moon info to update package metadata and ensure interfaces are consistent, which completed successfully.
  • Ran moon fmt to format changes, which completed successfully.
  • Ran the full test suite with moon test, and all tests passed: Total tests: 5632, passed: 5632, failed: 0.

Codex Task


Open with Devin

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 2569

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.005%) to 95.932%

Files with Coverage Reduction New Missed Lines %
json/json.mbt 1 99.12%
Totals Coverage Status
Change from base Build 2548: -0.005%
Covered Lines: 11909
Relevant Lines: 12414

💛 - Coveralls

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants