Skip to content

encoding/json/v2: add new JSON API behind a GOEXPERIMENT=jsonv2 guard #71845

Closed

Description

@neild

This is an adjunct proposal to #71497.

#71497 proposes adding a new JSON API, consisting of encoding/json/v2 and encoding/json/jsontext packages. The existing encoding/json package is modified to use the new v2 implementation internally. Several new functions are added to encoding/json. See that proposal for details.

The proposed new API is implemented in github.com/go-json-experiment/json.

I propose that we merge the implementation in github.com/go-json-experiment/json into std immediately, enabled only when the GOEXPERIMENT=jsonv2 experiment flag is set.

When the jsonv2 experiment flag is not enabled, there will be no user-visible changes to std. The encoding/json package will exist exactly as it is now, and the proposed new packages will not exist.

When GOEXPERIMENT=jsonv2 is set:

  • The new encoding/json/v2 and encoding/json/jsontext packages will exist.
  • The encoding/json package will be implemented in terms of encoding/json/v2.
  • The encoding/json package will include the new APIs proposed in encoding/json/v2: new API for encoding/json #71497.

The experimental API will not be bound by the Go compatibility promise and will evolve as updates are made to #71497.

If #71497 isn't approved in time for Go 1.25, we can either ship 1.25 with the GOEXPERIMENT guard or revert the experimental API in the 1.25 release. If #71497 is rejected, we'll remove the experimental package.

This proposal presumes that while there are still details being resolved, #71497 is on track for acceptance and we're happy with the general structure of the proposed API. Merging it into the main go repository prior to acceptance will make it easier for users to test out the new implementation.

Activity

  1. added this to the Proposal milestone on Feb 19, 2025
  2. moved this to Incoming in Proposalson Feb 19, 2025
  3. mvdan commented on Feb 23, 2025

    @mvdan
    Member

    Worth noting that one alternative would be to publish the entire code under e.g. x/exp/json once the proposal is approved, and use build tags such as //go:build go1.25 to forward the implementation (funcs, types, etc) to std once it lands there.

    I see a few advantages to that mechanism:

    1. Once the proposal is accepted and the API can be considered frozen, it lets downstreams start using it without waiting for the next Go release. This is particularly important for downstream library projects, as they tend to support two major Go versions. So if we were to merge into std for go1.25.0 being released in August 2025, many downstreams would have to wait until February 2026 to start importing it - even if just to implement new marshaler methods.
    2. It skips the CUE_EXPERIMENT knob entirely, which could cause some transition pain over the next year or two, such as some projects not working correctly with (or without) the experiment enabled.
    3. Placing the API under x/exp/json first allows us to delay adding it to std until late in the release cycle if we wish to, e.g. go1.25rc.1, reducing the chances that we need to do a big noisy revert if something goes wrong before then.
  4. seankhliao commented on Feb 23, 2025

    @seankhliao
    Member

    given it's already in an external module, I'm not sure what another copy in x/exp would gain us?

  5. mvdan commented on Feb 23, 2025

    @mvdan
    Member

    x/exp is part of the Go project, which brings many benefits - Gerrit, CI, the rest of the reviewers and approvers. Plus, the import path blesses it as official to users, whereas https://github.com/go-json-experiment is pretty much just a third party org.

  6. seankhliao commented on Feb 23, 2025

    @seankhliao
    Member

    an external module wouldn't benefit any existing users of encoding/json (which right now is ~all of them), without rewriting their imports, and reverting when it's released.
    Plus, existing users would be faced with multiple transitions from go-json-experiment -> x/exp -> json/v2
    x/exp has the added negative of bringing in a lot of other experimental packages, which aren't fully deprecated yet, but all versioned together.

  7. neild commented on Feb 24, 2025

    @neild
    ContributorAuthor

    The primary purpose of this proposal is to make it easier to test the proposed new implementation of the encoding/json package. An x/ package doesn't help with that.

  8. aclements commented on Mar 6, 2025

    @aclements
    Member

    This seems reasonable. @ianlancetaylor and I would like to at least look over #71497 because we start moving this forward. We plan to do that in the next week. Assuming it passes our sniff test, I think we can proceed with the GOEXPERIMENT=jsonv2 proposal.

  9. cespare commented on Mar 6, 2025

    @cespare
  10. moved this from Incoming to Active in Proposalson Mar 6, 2025
  11. aclements commented on Mar 6, 2025

    @aclements
    Member

    This proposal has been added to the active column of the proposals project
    and will now be reviewed at the weekly proposal review meetings.
    — aclements for the proposal review group

  12. aclements commented on Mar 12, 2025

    @aclements
    Member

    @ianlancetaylor and I looked over #71497 and are happy enough with it to move forward with this proposal to expose it behind a GOEXPERIMENT.

  13. 34 remaining items

  14. dsnet commented on Aug 5, 2025

    @dsnet
    Member

    Sure, I'd be happy to. When are we targeting Go 1.25 release?

  15. cherrymui commented on Aug 5, 2025

    @cherrymui
    Member

    Thank you!
    Go 1.25 is scheduled to be released next week. We're planning a series of blog posts for 1.25 features after the release. Later August would be a good time, and it could be flexible. Let me know what time is convenient for you. Thanks.

  16. cherrymui commented on Aug 15, 2025

    @cherrymui
    Member

    Hi @dsnet , just follow up on the blog post. Now that Go 1.25 is released, will you be able to work on a draft? Ideally if you could get a draft ready for review around the last week of August, and we can get the blog published in the first week of September, that would great. Let me know what time is convenient for you. Thanks.

  17. cherrymui commented on Aug 28, 2025

    @cherrymui
    Member

    Hi @dsnet , just checking in -- do you have an update on the timeline? Would you be able to prepare the blog draft this week for publishing next week? Let me know what time works best for you. Thanks!

  18. dsnet commented on Aug 29, 2025

    @dsnet
    Member

    I'll have a CL for the blog post out by EOD, which means that a release next week would be good.

  19. dsnet commented on Sep 1, 2025

    @dsnet
    Member

    I apologize, I'm out traveling for Labor Day weekend. I have most of it written, hope to send it out soon.

  20. gopherbot commented on Sep 4, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/700377 mentions this issue: _content/blog/jsonv2-exp.md: new blog post

  21. moved this from Done to Needs review in json/v2 working groupon Nov 22, 2025
  22. moved this from Needs review to Done in json/v2 working groupon Nov 22, 2025
  23. locked and limited conversation to collaborators on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions