Skip to content

Improve JSON serialization#215

Open
turbolent wants to merge 6 commits into
mainfrom
bastian/escape-json-improvements
Open

Improve JSON serialization#215
turbolent wants to merge 6 commits into
mainfrom
bastian/escape-json-improvements

Conversation

@turbolent

@turbolent turbolent commented Jun 17, 2026

Copy link
Copy Markdown
Member

Description

Improve Serialize further:

  • Also defensively escape <, >, & (XSS when metadata is rendered in a browser) and
    U+2028 / U+2029 (valid JSON but invalid in JS string literals)

  • Improve efficiency by using StringBuilder

    All serialization now appends to a single shared StringBuilder instead of building and joining intermediate strings/arrays.

    Public functions keep their signatures and simply create a builder and delegate to private append* helpers.

  • Add support for additional scalar types

    Added Fix64, Fix128, and UFix128 (previously only UFix64 was handled among fixed-point types).


For contributor use:

  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.12281% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/contracts/utils/Serialize.cdc 99.12% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@SupunS SupunS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@janezpodhostnik

Copy link
Copy Markdown
Contributor

Nice, thanks!

Base automatically changed from janez/escape-json to main June 18, 2026 20:59
@turbolent turbolent force-pushed the bastian/escape-json-improvements branch from 582a462 to 908903b Compare June 18, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: 👀 In Review

Development

Successfully merging this pull request may close these issues.

4 participants