Skip to content

Add options to Schema.fromJsonString - #6707

Merged
gcanti merged 2 commits into
mainfrom
feat/schema-json-string-options
Jul 28, 2026
Merged

Add options to Schema.fromJsonString#6707
gcanti merged 2 commits into
mainfrom
feat/schema-json-string-options

Conversation

@gcanti

@gcanti gcanti commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added configurable JSON string parsing and formatting to Schema.fromJsonString.
    • Supports reviver, replacer, and space options for transformation and pretty-printed output.
  • Improvements
    • Updated internal JSON-decoding usage to rely on Schema.fromJsonString(Schema.Unknown).
    • Added a public JsonReplacer type for stringifyJson configuration.
  • Documentation
    • Refined docs and examples to explain parse/decode and encode/stringify flows.
  • Tests
    • Added coverage for reviver, replacer, and space behavior.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 28, 2026
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c3420a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 enhancement New feature or request labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3a836e8-a466-441f-a832-aafdd53ce1e6

📥 Commits

Reviewing files that changed from the base of the PR and between 5529a5b and 5c3420a.

📒 Files selected for processing (5)
  • .changeset/internal-json-string-schema.md
  • packages/effect/src/Schema.ts
  • packages/effect/src/SchemaGetter.ts
  • packages/effect/src/SchemaTransformation.ts
  • packages/effect/test/schema/Schema.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • .changeset/internal-json-string-schema.md
  • packages/effect/test/schema/Schema.test.ts
  • packages/effect/src/SchemaTransformation.ts
  • packages/effect/src/Schema.ts

📝 Walkthrough

Walkthrough

Schema.fromJsonString now accepts JSON parsing and formatting options through a configurable transformation factory. UnknownFromJsonString is internal, consumers use Schema.fromJsonString(Schema.Unknown), and tests cover revivers, replacers, and spacing.

Changes

JSON string schema configuration

Layer / File(s) Summary
Configurable transformation factory
packages/effect/src/SchemaTransformation.ts, packages/effect/src/SchemaGetter.ts
fromJsonString forwards reviver, replacer, and space options to JSON parsing and stringifying.
Schema API and consumer migration
packages/effect/src/Schema.ts, packages/effect/src/unstable/http/UrlParams.ts, packages/tools/api-diff/src/Json.ts, packages/effect/test/schema/Schema.test.ts, .changeset/internal-json-string-schema.md
Schema.fromJsonString accepts JSON options, UnknownFromJsonString is marked internal, consumers use Schema.fromJsonString(Schema.Unknown), and option behavior is tested and documented.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SchemaFromJsonString
  participant SchemaTransformationFromJsonString
  participant SchemaGetter
  Caller->>SchemaFromJsonString: provide schema and JSON options
  SchemaFromJsonString->>SchemaTransformationFromJsonString: create configured transformation
  SchemaTransformationFromJsonString->>SchemaGetter: configure parseJson and stringifyJson
  SchemaGetter-->>Caller: decode or encode JSON string
Loading

Possibly related PRs

  • Effect-TS/effect#6633: Changes SchemaGetter.stringifyJson behavior for cases where JSON.stringify returns undefined, in the same implementation area.

Suggested reviewers: tim-smart

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.29 KB 6.29 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.89 KB 19.89 KB 0.00 KB (0.00%)
differ.ts 19.06 KB 19.06 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.45 KB 7.45 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.84 KB 18.84 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.75 KB 28.75 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.05 KB 25.05 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.96 KB 12.96 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.62 KB 21.62 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.07 KB 24.07 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.97 KB 18.97 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.69 KB 18.69 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.56 KB 18.56 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.19 KB 22.19 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.23 KB 19.23 KB 0.00 KB (0.00%)
schema.ts 18.10 KB 18.10 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/effect/src/SchemaTransformation.ts`:
- Around line 1621-1623: The JSON option types currently infer only the array
replacer overload. Define a shared replacer type that includes both callback and
array forms, then reuse it for the replacer fields in SchemaTransformation,
Schema, and the corresponding SchemaGetter options; leave reviver and space
typing unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2491bca9-e8d8-4cbc-8a36-149150708f35

📥 Commits

Reviewing files that changed from the base of the PR and between 5d52d9d and 5529a5b.

📒 Files selected for processing (6)
  • .changeset/internal-json-string-schema.md
  • packages/effect/src/Schema.ts
  • packages/effect/src/SchemaTransformation.ts
  • packages/effect/src/unstable/http/UrlParams.ts
  • packages/effect/test/schema/Schema.test.ts
  • packages/tools/api-diff/src/Json.ts

Comment thread packages/effect/src/SchemaTransformation.ts
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 28, 2026
@gcanti
gcanti merged commit 1a7ce81 into main Jul 28, 2026
15 checks passed
@gcanti
gcanti deleted the feat/schema-json-string-options branch July 28, 2026 19:07
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in PR Backlog Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant