pkg.go.dev Open in urlscan Pro
2600:1901:0:f535::  Public Scan

Submitted URL: http://google.golang.org/protobuf/encoding/protojson
Effective URL: https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson
Submission: On September 13 via api from US — Scanned from DE

Form analysis 3 forms found in the DOM

/search

<form class="go-InputGroup go-ShortcutKey go-SearchForm-form" action="/search" data-shortcut="/" data-shortcut-alt="search" data-gtmc="search form" aria-label="Search for a package" role="search">
  <input name="q" class="go-Input js-searchFocus" aria-label="Search for a package" type="search" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="Search packages or symbols" value="">
  <input name="m" value="" hidden="">
  <button class="go-Button go-Button--inverted" aria-label="Submit search">
    <img class="go-Icon" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt="">
  </button>
</form>

DIALOG

<form method="dialog" data-gmtc="jump to form" aria-label="Jump to Identifier">
  <div class="Dialog-title go-Modal-header">
    <h2>Jump to</h2>
    <button class="go-Button go-Button--inline" type="button" data-modal-close="" data-gtmc="modal button" aria-label="Close">
      <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="">
    </button>
  </div>
  <div class="JumpDialog-filter">
    <input class="JumpDialog-input go-Input" autocomplete="off" type="text">
  </div>
  <div class="JumpDialog-body go-Modal-body">
    <div class="JumpDialog-list"></div>
  </div>
  <div class="go-Modal-actions">
    <button class="go-Button" data-test-id="close-dialog">Close</button>
  </div>
</form>

DIALOG

<form method="dialog">
  <div class="go-Modal-header">
    <h2>Keyboard shortcuts</h2>
    <button class="go-Button go-Button--inline" type="button" data-modal-close="" data-gtmc="modal button" aria-label="Close">
      <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="">
    </button>
  </div>
  <div class="go-Modal-body">
    <table>
      <tbody>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>?</strong>
          </td>
          <td> : This menu</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>/</strong>
          </td>
          <td> : Search site</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>f</strong> or <strong>F</strong>
          </td>
          <td> : Jump to</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key"><strong>y</strong> or <strong>Y</strong></td>
          <td> : Canonical URL</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="go-Modal-actions">
    <button class="go-Button" data-test-id="close-dialog">Close</button>
  </div>
</form>

Text Content

Skip to Main Content
 * Why Go
   * Case Studies
     
     Common problems companies solve with Go
   
   * Use Cases
     
     Stories about how and why companies use Go
   
   * Security Policy
     
     How Go can help keep you secure by default
 * Learn
 * Docs
   * Effective Go
     
     Tips for writing clear, performant, and idiomatic Go code
   
   * Go User Manual
     
     A complete introduction to building software with Go
   
   * Standard library
     
     Reference documentation for Go's standard library
   
   * Release Notes
     
     Learn what's new in each Go release
 * Packages
 * Community
   * Recorded Talks
     
     Videos from prior events
   
   * Meetups
     
     Meet other local Go developers
   
   * Conferences
     
     Learn and network with Go developers from around the world
   
   * Go blog
     
     The Go project's official blog.
   
   * Go project
     
     Get help and stay informed from Go
   
   * Get connected
     
     
     
     

 * Why Go
   Why Go
    * Case Studies
    * Use Cases
    * Security Policy

 * Learn
 * Docs
   Docs
    * Effective Go
    * Go User Manual
    * Standard library
    * Release Notes

 * Packages
 * Community
   Community
    * Recorded Talks
    * Meetups
    * Conferences
    * Go blog
    * Go project
    * Get connected
      


 1. Discover Packages
 2. google.golang.org/protobuf
 3. encoding
 4. protojson


PROTOJSON

package
Version: v1.34.2
Opens a new window with list of versions in this module.
Latest Latest

This package is not in the latest version of its module.

Go to latest Published: Jun 11, 2024 License: BSD-3-Clause
Opens a new window with license information.
Imports: 21
Opens a new window with list of imports.
Imported by: 5,304
Opens a new window with list of known importers.
Main Versions Licenses Imports Imported By


DETAILS

 * Valid go.mod file
   
   The Go module system was introduced in Go 1.11 and is the official dependency
   management solution for Go.

 * Redistributable license
   
   Redistributable licenses place minimal restrictions on how software can be
   used, modified, and redistributed.

 * Tagged version
   
   Modules with tagged versions give importers more predictable builds.

 * Stable version
   
   When a project reaches major version v1 it is considered stable.

 * Learn more about best practices


REPOSITORY

github.com/protocolbuffers/protobuf-go


LINKS

 * Open Source Insights

Jump to ...
 * Documentation
   * Overview
   * Index
   * Constants
   * Variables
   * Functions
     * Format(m)
     * Marshal(m)
     * Unmarshal(b, m)
   * Types
     * type MarshalOptions
       * (o) Format(m)
       * (o) Marshal(m)
       * (o) MarshalAppend(b, m)
     * type UnmarshalOptions
       * (o) Unmarshal(b, m)
 * Source Files

DocumentationSource
FilesOverviewIndexConstantsVariablesFunctionsTypesFormat(m)Marshal(m)Unmarshal(b,
m)type MarshalOptionstype UnmarshalOptions(o) Format(m)(o) Marshal(m)(o)
MarshalAppend(b, m)(o) Unmarshal(b, m)


DOCUMENTATION ¶


OVERVIEW ¶

Package protojson marshals and unmarshals protocol buffer messages as JSON
format. It follows the guide at
https://protobuf.dev/programming-guides/proto3#json.

This package produces a different output than the standard encoding/json
package, which does not operate correctly on protocol buffer messages.


INDEX ¶

 * func Format(m proto.Message) string
 * func Marshal(m proto.Message) ([]byte, error)
 * func Unmarshal(b []byte, m proto.Message) error
 * type MarshalOptions
 * * func (o MarshalOptions) Format(m proto.Message) string
   * func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error)
   * func (o MarshalOptions) MarshalAppend(b []byte, m proto.Message) ([]byte,
     error)
 * type UnmarshalOptions
 * * func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error


CONSTANTS ¶

This section is empty.


VARIABLES ¶

This section is empty.


FUNCTIONS ¶

FUNC FORMAT ¶

func Format(m proto.Message) string

Format formats the message as a multiline string. This function is only intended
for human consumption and ignores errors. Do not depend on the output being
stable. Its output will change across different builds of your program, even
when using the same version of the protobuf module.

FUNC MARSHAL ¶

func Marshal(m proto.Message) ([]byte, error)

Marshal writes the given proto.Message in JSON format using default options. Do
not depend on the output being stable. Its output will change across different
builds of your program, even when using the same version of the protobuf module.

FUNC UNMARSHAL ¶

func Unmarshal(b []byte, m proto.Message) error

Unmarshal reads the given []byte into the given proto.Message. The provided
message must be mutable (e.g., a non-nil pointer to a message).


TYPES ¶

TYPE MARSHALOPTIONS ¶

type MarshalOptions struct {
	pragma.NoUnkeyedLiterals

	// Multiline specifies whether the marshaler should format the output in
	// indented-form with every textual element on a new line.
	// If Indent is an empty string, then an arbitrary indent is chosen.
	Multiline bool

	// Indent specifies the set of indentation characters to use in a multiline
	// formatted output such that every entry is preceded by Indent and
	// terminated by a newline. If non-empty, then Multiline is treated as true.
	// Indent can only be composed of space or tab characters.
	Indent string

	// AllowPartial allows messages that have missing required fields to marshal
	// without returning an error. If AllowPartial is false (the default),
	// Marshal will return error if there are any missing required fields.
	AllowPartial bool

	// UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
	// field names.
	UseProtoNames bool

	// UseEnumNumbers emits enum values as numbers.
	UseEnumNumbers bool

	// EmitUnpopulated specifies whether to emit unpopulated fields. It does not
	// emit unpopulated oneof fields or unpopulated extension fields.
	// The JSON value emitted for unpopulated fields are as follows:
	//  ╔═══════╤════════════════════════════╗
	//  ║ JSON  │ Protobuf field             ║
	//  ╠═══════╪════════════════════════════╣
	//  ║ false │ proto3 boolean fields      ║
	//  ║ 0     │ proto3 numeric fields      ║
	//  ║ ""    │ proto3 string/bytes fields ║
	//  ║ null  │ proto2 scalar fields       ║
	//  ║ null  │ message fields             ║
	//  ║ []    │ list fields                ║
	//  ║ {}    │ map fields                 ║
	//  ╚═══════╧════════════════════════════╝
	EmitUnpopulated bool

	// EmitDefaultValues specifies whether to emit default-valued primitive fields,
	// empty lists, and empty maps. The fields affected are as follows:
	//  ╔═══════╤════════════════════════════════════════╗
	//  ║ JSON  │ Protobuf field                         ║
	//  ╠═══════╪════════════════════════════════════════╣
	//  ║ false │ non-optional scalar boolean fields     ║
	//  ║ 0     │ non-optional scalar numeric fields     ║
	//  ║ ""    │ non-optional scalar string/byte fields ║
	//  ║ []    │ empty repeated fields                  ║
	//  ║ {}    │ empty map fields                       ║
	//  ╚═══════╧════════════════════════════════════════╝
	//
	// Behaves similarly to EmitUnpopulated, but does not emit "null"-value fields,
	// i.e. presence-sensing fields that are omitted will remain omitted to preserve
	// presence-sensing.
	// EmitUnpopulated takes precedence over EmitDefaultValues since the former generates
	// a strict superset of the latter.
	EmitDefaultValues bool

	// Resolver is used for looking up types when expanding google.protobuf.Any
	// messages. If nil, this defaults to using protoregistry.GlobalTypes.
	Resolver interface {
		protoregistry.ExtensionTypeResolver
		protoregistry.MessageTypeResolver
	}
}

MarshalOptions is a configurable JSON format marshaler.

FUNC (MARSHALOPTIONS) FORMAT ¶

func (o MarshalOptions) Format(m proto.Message) string

Format formats the message as a string. This method is only intended for human
consumption and ignores errors. Do not depend on the output being stable. Its
output will change across different builds of your program, even when using the
same version of the protobuf module.

FUNC (MARSHALOPTIONS) MARSHAL ¶

func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error)

Marshal marshals the given proto.Message in the JSON format using options in Do
not depend on the output being stable. Its output will change across different
builds of your program, even when using the same version of the protobuf module.

FUNC (MARSHALOPTIONS) MARSHALAPPEND ¶ ADDED IN V1.31.0

func (o MarshalOptions) MarshalAppend(b []byte, m proto.Message) ([]byte, error)

MarshalAppend appends the JSON format encoding of m to b, returning the result.

TYPE UNMARSHALOPTIONS ¶

type UnmarshalOptions struct {
	pragma.NoUnkeyedLiterals

	// If AllowPartial is set, input for messages that will result in missing
	// required fields will not return an error.
	AllowPartial bool

	// If DiscardUnknown is set, unknown fields and enum name values are ignored.
	DiscardUnknown bool

	// Resolver is used for looking up types when unmarshaling
	// google.protobuf.Any messages or extension fields.
	// If nil, this defaults to using protoregistry.GlobalTypes.
	Resolver interface {
		protoregistry.MessageTypeResolver
		protoregistry.ExtensionTypeResolver
	}

	// RecursionLimit limits how deeply messages may be nested.
	// If zero, a default limit is applied.
	RecursionLimit int
}

UnmarshalOptions is a configurable JSON format parser.

FUNC (UNMARSHALOPTIONS) UNMARSHAL ¶

func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error

Unmarshal reads the given []byte and populates the given proto.Message using
options in the UnmarshalOptions object. It will clear the message first before
setting the fields. If it returns an error, the given message may be partially
set. The provided message must be mutable (e.g., a non-nil pointer to a
message).


SOURCE FILES ¶

View all Source files
 * decode.go
 * doc.go
 * encode.go
 * well_known_types.go

Click to show internal directories.
Click to hide internal directories.

Why Go Use Cases Case Studies
Get Started Playground Tour Stack Overflow Help
Packages Standard Library Sub-repositories About Go Packages
About Download Blog Issue Tracker Release Notes Brand Guidelines Code of Conduct
Connect Twitter GitHub Slack r/golang Meetup Golang Weekly
 * Copyright
 * Terms of Service
 * Privacy Policy
 * Report an Issue

 * Theme Toggle

 * Shortcuts Modal


JUMP TO



Close


KEYBOARD SHORTCUTS

? : This menu / : Search site f or F : Jump to y or Y : Canonical URL

Close
go.dev uses cookies from Google to deliver and enhance the quality of its
services and to analyze traffic. Learn more.
Okay