CodeSampleX

Sample

google.golang.org/protobuf v1.36.12: Control JSON formatting and parsing of Protocol Buffers messages using protojson MarshalOptions and UnmarshalOptions

Verified sample for golang google.golang.org/protobuf v1.36.12: Control JSON formatting and parsing of Protocol Buffers messages using protojson…

sha256:b4eaaa06b9ceab6e52f7e4023b4e801213a60c5d5835efcfda2490e38d021c6c

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment go linux x64 go go go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-17
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-18

Case

HOW
Goal
Control JSON formatting and parsing of Protocol Buffers messages using protojson MarshalOptions and UnmarshalOptions
Packages
Symbols
  • google.golang.org/protobuf/encoding/protojson.Marshal
  • google.golang.org/protobuf/encoding/protojson.MarshalOptions
  • google.golang.org/protobuf/encoding/protojson.Unmarshal
  • google.golang.org/protobuf/encoding/protojson.UnmarshalOptions
Environment
go
Created
2026-08-17T14:45:25Z

Contract

  1. By default protojson.Marshal omits unpopulated or zero-valued fields, but protojson.MarshalOptions with EmitUnpopulated set to true includes default values for scalar fields, empty arrays for repeated fields, and null for unset message fields.
  2. Setting protojson.MarshalOptions.UseProtoNames to true formats JSON keys using original snake_case protobuf field names instead of camelCase json_name.
  3. Setting protojson.MarshalOptions.UseEnumNumbers to true serializes enum values as their numeric integers rather than enum string identifiers.
  4. Well-known types such as google.protobuf.Timestamp and google.protobuf.Struct serialize directly to RFC 3339 formatted strings and native JSON objects respectively.
  5. By default protojson.Unmarshal rejects JSON payloads containing unknown keys with an error, whereas protojson.UnmarshalOptions with DiscardUnknown set to true silently discards unrecognized fields.

Files

  • NOTES.md
  • csx.json
  • go.mod
  • go.sum
  • protojson_test.go

Download the source artifact (tar.gz)

Origin Seeder

csx-seed