json_util.h

#include <google/protobuf/util/json_util.h>
namespace google::protobuf::util

Utility functions to convert between protobuf binary format and proto3 JSON format.

Classes in this file

File Members

These definitions are not part of any class.
typedef
JsonPrintOptions JsonOptions
DEPRECATED. Use JsonPrintOptions instead.
util::Status
MessageToJsonString(const Message & message, string * output, const JsonOptions & options)
Converts from protobuf message to JSON. more...
util::Status
MessageToJsonString(const Message & message, string * output)
util::Status
JsonStringToMessage(const string & input, Message * message, const JsonParseOptions & options)
Converts from JSON to protobuf message. more...
util::Status
JsonStringToMessage(const string & input, Message * message)
util::Status
BinaryToJsonStream(TypeResolver * resolver, const string & type_url, io::ZeroCopyInputStream * binary_input, io::ZeroCopyOutputStream * json_output, const JsonPrintOptions & options)
Converts protobuf binary data to JSON. more...
util::Status
BinaryToJsonStream(TypeResolver * resolver, const string & type_url, io::ZeroCopyInputStream * binary_input, io::ZeroCopyOutputStream * json_output)
util::Status
BinaryToJsonString(TypeResolver * resolver, const string & type_url, const string & binary_input, string * json_output, const JsonPrintOptions & options)
util::Status
BinaryToJsonString(TypeResolver * resolver, const string & type_url, const string & binary_input, string * json_output)
util::Status
JsonToBinaryStream(TypeResolver * resolver, const string & type_url, io::ZeroCopyInputStream * json_input, io::ZeroCopyOutputStream * binary_output, const JsonParseOptions & options)
Converts JSON data to protobuf binary format. more...
util::Status
JsonToBinaryStream(TypeResolver * resolver, const string & type_url, io::ZeroCopyInputStream * json_input, io::ZeroCopyOutputStream * binary_output)
util::Status
JsonToBinaryString(TypeResolver * resolver, const string & type_url, const string & json_input, string * binary_output, const JsonParseOptions & options)
util::Status
JsonToBinaryString(TypeResolver * resolver, const string & type_url, const string & json_input, string * binary_output)

util::Status util::MessageToJsonString(
        const Message & message,
        string * output,
        const JsonOptions & options)

Converts from protobuf message to JSON.

This is a simple wrapper of BinaryToJsonString(). It will use the DescriptorPool of the passed-in message to resolve Any types.


util::Status util::JsonStringToMessage(
        const string & input,
        Message * message,
        const JsonParseOptions & options)

Converts from JSON to protobuf message.

This is a simple wrapper of JsonStringToBinary(). It will use the DescriptorPool of the passed-in message to resolve Any types.


util::Status util::BinaryToJsonStream(
        TypeResolver * resolver,
        const string & type_url,
        io::ZeroCopyInputStream * binary_input,
        io::ZeroCopyOutputStream * json_output,
        const JsonPrintOptions & options)

Converts protobuf binary data to JSON.

The conversion will fail if:

1. TypeResolver fails to resolve a type.
2. input is not valid protobuf wire format, or conflicts with the type
   information returned by TypeResolver.

Note that unknown fields will be discarded silently.


util::Status util::JsonToBinaryStream(
        TypeResolver * resolver,
        const string & type_url,
        io::ZeroCopyInputStream * json_input,
        io::ZeroCopyOutputStream * binary_output,
        const JsonParseOptions & options)

Converts JSON data to protobuf binary format.

The conversion will fail if:

1. TypeResolver fails to resolve a type.
2. input is not valid JSON format, or conflicts with the type
   information returned by TypeResolver.

struct JsonParseOptions

#include <google/protobuf/util/json_util.h>
namespace google::protobuf::util

Members

bool
ignore_unknown_fields
Whether to ignore unknown JSON fields during parsing.
JsonParseOptions()

struct JsonPrintOptions

#include <google/protobuf/util/json_util.h>
namespace google::protobuf::util

Members

bool
add_whitespace
Whether to add spaces, line breaks and indentation to make the JSON output easy to read.
bool
always_print_primitive_fields
Whether to always print primitive fields. more...
JsonPrintOptions()

boolJsonPrintOptions::always_print_primitive_fields

Whether to always print primitive fields.

By default primitive fields with default values will be omitted in JSON joutput. For example, an int32 field set to 0 will be omitted. Set this flag to true will override the default behavior and print primitive fields regardless of their values.