All Projects β†’ mitchellh β†’ Protoc Gen Go Json

mitchellh / Protoc Gen Go Json

Licence: mit
Protobuf compiler plugin to generate Go JSON Marshal/Unmarshal implementations for messages using jsonpb.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Protoc Gen Go Json

Pufferdb
🐑 An Android & JVM key-value storage powered by Protobuf and Coroutines
Stars: ✭ 91 (-17.27%)
Mutual labels:  protobuf
Protoc Jar
Protocol Buffers protobuf compiler - multi-platform executable protoc JAR and API
Stars: ✭ 103 (-6.36%)
Mutual labels:  protobuf
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+47450%)
Mutual labels:  protobuf
Protoc Gen Gotag
Add custom struct tags to protobuf generated structs
Stars: ✭ 97 (-11.82%)
Mutual labels:  protobuf
Rxcache
A local reactive cache for Java and Android. Now, it supports heap memory、off-heap memory and disk cache.
Stars: ✭ 102 (-7.27%)
Mutual labels:  protobuf
Carbonzipper
proxy to transparently merge graphite carbon backends
Stars: ✭ 104 (-5.45%)
Mutual labels:  protobuf
Flow Pipeline
A set of tools and examples to run a flow-pipeline (sFlow, NetFlow)
Stars: ✭ 86 (-21.82%)
Mutual labels:  protobuf
Pbandk
Kotlin Code Generator and Runtime for Protocol Buffers
Stars: ✭ 110 (+0%)
Mutual labels:  protobuf
Orion
Orion is a small lightweight framework written around grpc/protobuf with the aim to shorten time to build microservices at Carousell.
Stars: ✭ 101 (-8.18%)
Mutual labels:  protobuf
Benchmark Grpc Protobuf Vs Http Json
Benchmarks comparing gRPC+Protobuf vs JSON+HTTP in Go
Stars: ✭ 106 (-3.64%)
Mutual labels:  protobuf
Protein
Encoding/decoding library for Protobuf with schema-versioning and runtime-decoding capabilities.
Stars: ✭ 96 (-12.73%)
Mutual labels:  protobuf
Protobuf
Python implementation of Protocol Buffers data types with dataclasses support
Stars: ✭ 101 (-8.18%)
Mutual labels:  protobuf
Protoc Gen Struct Transformer
Transformation functions generator for Protocol Buffers.
Stars: ✭ 105 (-4.55%)
Mutual labels:  protobuf
Centrifuge Go
Go WebSocket client for Centrifugo and Centrifuge library
Stars: ✭ 95 (-13.64%)
Mutual labels:  protobuf
Protodot
transforming your .proto files into .dot files (and .svg, .png if you happen to have graphviz installed)
Stars: ✭ 107 (-2.73%)
Mutual labels:  protobuf
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (-18.18%)
Mutual labels:  protobuf
Prost
PROST! a Protocol Buffers implementation for the Rust Language
Stars: ✭ 1,396 (+1169.09%)
Mutual labels:  protobuf
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+1397.27%)
Mutual labels:  protobuf
Twirp
PHP port of Twitch's Twirp RPC framework
Stars: ✭ 108 (-1.82%)
Mutual labels:  protobuf
Gopherlabs
The Ultimate Workshop Track for #golang Developer
Stars: ✭ 106 (-3.64%)
Mutual labels:  protobuf

protoc-gen-go-json

This is a plugin for the Google Protocol Buffers compiler protoc that generates code to implement json.Marshaler and json.Unmarshaler using jsonpb.

This enables Go-generated protobuf messages to be embedded directly within other structs and encoded with the standard JSON library, since the standard encoding/json library can't encode certain protobuf messages such as those that contain oneof fields.

Install

go get github.com/mitchellh/protoc-gen-go-json

Also required:

Usage

Define your messages like normal:

syntax = "proto3";

message Request {
  oneof kind {
    string name = 1;
    int32  code = 2;
  }
}

The example message purposely uses a oneof since this won't work by default with encoding/json. Next, generate the code:

protoc --go_out=. --go-json_out=. request.proto

Your output should contain a file request.pb.json.go which contains the implementation of json.Marshal/Unmarshal for all your message types. You can then encode your messages using standard encoding/json:

import "encoding/json"

// Marshal
bs, err := json.Marshal(&Request{
  Kind: &Kind_Name{
    Name: "alice",
  },
}

// Unmarshal
var result Request
json.Unmarshal(bs, &result)

Options

The generator supports options you can specify via the command-line:

  • enums_as_ints - Render enums as integers instead of strings.
  • emit_defaults - Render fields with zero values.
  • orig_name - Use original (.proto file) name for fields.
  • allow_unknown - Allow messages to contain unknown fields when unmarshaling

These can be set as part of the --go-json_out value:

protoc --go-json_out=emit_defaults:.

You can specify multiple using a ,:

protoc --go-json_out=enums_as_ints,emit_defaults:.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].