Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-Proto canonical mapping needs to be documented #224

Closed
oaktowner opened this issue Feb 27, 2015 · 10 comments
Closed

JSON-Proto canonical mapping needs to be documented #224

oaktowner opened this issue Feb 27, 2015 · 10 comments

Comments

@oaktowner
Copy link

No description provided.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jan 20, 2016

Proto3 language guide also has a section about JSON mapping:
https://developers.google.com/protocol-buffers/docs/proto3#json

We will publish a more detailed JSON spec doc later.

@karthequian
Copy link

Hello, has there been any progress on this? Or is it possible that I can help with this if there's already some text that we'd like to add?

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 26, 2016

Sorry, we are not ready to publish the doc yet. If you have specific questions about the JSON formatting of some proto types, can you post the questions here? If you are working on implementing a JSON serializer conforming to the spec, you can look at our conformance test which covers a lot of the JSON mapping details:
https://github.com/google/protobuf/blob/master/conformance/conformance_test.cc#L623

@xfxyjwf xfxyjwf self-assigned this Apr 26, 2016
@ghost
Copy link

ghost commented Jul 7, 2016

The json serialization does not contain message type information, so while parsing we need to provide a builder:
In Java:
JsonFormat.Parser
merge(String json, Builder builder);
merge(Reader json, Builder builder);

How can we make the json representation self-contained by encoding the message type info in it as well; so that parser can detect the message type to parse into?

I think #1690 is exactly about this but for C++.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jul 7, 2016

@meta-coder Are you asking for a new API that looks like:

class Parser {
  public Message merge(String json);
}

? It's not clear to me how useful is this kind of API. Without knowing the type, how can you make use of the returned Message instance?

@ghost
Copy link

ghost commented Jul 7, 2016

In a way, I was. Including the type of the message in the json representation can be helpful in parsing. For comparison, the default serialization mechanism used by Java's ObjectOutputStream is to write the class of the object and the class signature at the beginning of the encoding.
Anyway, I realize I could use `oneof' to achieve what I want. Thanks.

@ofpiyush
Copy link

We have a service in JS that needs to implement protobuf to JSON and vice-versa for internal use and the UI.

We'd like to implement a canonical proto3 JSON serialiser/deserialiser.

I'll try to set up conformance tests, but something specifically for the spec would be really useful.

@TeBoring TeBoring reopened this Oct 22, 2018
@TeBoring TeBoring assigned TeBoring and unassigned xfxyjwf Oct 22, 2018
@TeBoring
Copy link
Contributor

We currently have docs here: https://developers.google.com/protocol-buffers/docs/proto3#json
We also implemented our json conformance test here: https://github.com/protocolbuffers/protobuf/blob/master/conformance/conformance_test_impl.cc
Is it enough to write your conformance test? @ofpiyush

@ofpiyush
Copy link

For unrelated reasons, we moved the service to Go and used it's serialiser/deserialiser. So I stopped looking into this.

Thanks for your help @TeBoring 👍

@elharo elharo assigned Logofile and unassigned TeBoring Oct 1, 2021
@acozzette acozzette assigned jskeet and unassigned Logofile Sep 1, 2022
bithium pushed a commit to bithium/protobuf that referenced this issue Sep 4, 2023
Implemented support for maps (generated & reflection), and improved reflection API
@Logofile Logofile self-assigned this Jan 3, 2024
@Logofile
Copy link
Member

Logofile commented Jan 4, 2024

It appears that those who contributed to this issue have all found workarounds or are otherwise no longer blocked. I'm closing this issue, but feel free to reopen it with additional details if this is still a problem.

@Logofile Logofile closed this as completed Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants