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

Serializing protobufs to json #351

Closed
mwildehahn opened this Issue Nov 6, 2015 · 8 comments

Comments

Projects
None yet
6 participants
@mwildehahn

mwildehahn commented Nov 6, 2015

with proto3, protocol buffers now have a standard json format, is there a way to leverage this with this library?

my use case is caching protocol buffers in local storage. currently i've been base64 encoding the messages before storing them. this becomes more complex with the Map type.

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Nov 18, 2015

Have you tried Message#encodeJSON?

@dcodeIO dcodeIO added the question label Nov 19, 2015

@lanttu

This comment has been minimized.

lanttu commented Dec 16, 2015

The method doesn't seem to use canonical proto3 JSON encoding as specfied in here: https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json

@joeblew99

This comment has been minimized.

joeblew99 commented Dec 17, 2015

Did you sort out if Google's support for json, makes bufferjs redundant ?

I suspect that bufferjs allows marshalling between json and PB client side, and grpc allows marshalling between the two server side at the facade.

I would like to know what the answer to this is from an architectural perspective.

@leeyeh

This comment has been minimized.

leeyeh commented Feb 23, 2016

+1.

My use case is to encode to and decode from the canonical formatted JSON data, since React Native's js-native bright is text-based.

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Nov 28, 2016

Closing this for now.

protobuf.js 6.0.0

Feel free to send a pull request if this is still a requirement.

@dcodeIO dcodeIO closed this Nov 28, 2016

@aidansteele

This comment has been minimized.

aidansteele commented Apr 11, 2017

@dcodeIO Sorry, it's not clear to me - is the issue closed because any changes discussed here are no longer relevant (due to rewrite) or because protobuf.js 6.x now supports the functionality?

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Apr 11, 2017

or because protobuf.js 6.x now supports the functionality

Not quite, but the default toJSON implementation of message instances should be close.

someMessage.toJSON();
// or
SomeMessage.toObject(someMessage, util.toJSONOptions);

Not yet supported:

  • "NaN", "Infinity" strings for floats
  • Any, Timestamp, Duration, Struct, Wrappers, FieldMask, ListValue, Value, NullValue are handled like messages

Feel free to reopen!

dcodeIO added a commit that referenced this issue Apr 11, 2017

New: Added 'json' conversion option for proto3 JSON mapping compatibi…
…lity of NaN and Infinity + additional documentation of util.toJSONOptions, see #351
@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Apr 11, 2017

Related: #677

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