package structpb

Import Path
	google.golang.org/protobuf/types/known/structpb (on go.dev)

Dependency Relation
	imports 8 packages, and imported by 4 packages

Involved Source Files Package structpb contains generated types for google/protobuf/struct.proto. The messages (i.e., Value, Struct, and ListValue) defined in struct.proto are used to represent arbitrary JSON. The Value message represents a JSON value, the Struct message represents a JSON object, and the ListValue message represents a JSON array. See https://json.org for more information. The Value, Struct, and ListValue types have generated MarshalJSON and UnmarshalJSON methods such that they serialize JSON equivalent to what the messages themselves represent. Use of these types with the "google.golang.org/protobuf/encoding/protojson" package ensures that they will be serialized as their JSON equivalent. Conversion to and from a Go interface The standard Go "encoding/json" package has functionality to serialize arbitrary types to a large degree. The Value.AsInterface, Struct.AsMap, and ListValue.AsSlice methods can convert the protobuf message representation into a form represented by interface{}, map[string]interface{}, and []interface{}. This form can be used with other packages that operate on such data structures and also directly with the standard json package. In order to convert the interface{}, map[string]interface{}, and []interface{} forms back as Value, Struct, and ListValue messages, use the NewStruct, NewList, and NewValue constructor functions. Example usage Consider the following example JSON object: { "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 27, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100" }, "phoneNumbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "office", "number": "646 555-4567" } ], "children": [], "spouse": null } To construct a Value message representing the above JSON object: m, err := structpb.NewValue(map[string]interface{}{ "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 27, "address": map[string]interface{}{ "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100", }, "phoneNumbers": []interface{}{ map[string]interface{}{ "type": "home", "number": "212 555-1234", }, map[string]interface{}{ "type": "office", "number": "646 555-4567", }, }, "children": []interface{}{}, "spouse": nil, }) if err != nil { ... // handle error } ... // make use of m as a *structpb.Value
Package-Level Type Names (total 11, in which 10 are exported)
/* sort exporteds by: | */
`ListValue` is a wrapper around a repeated field of values. The JSON representation for `ListValue` is JSON array. Repeated field of dynamically typed values. AsSlice converts x to a general-purpose Go slice. The slice elements are converted by calling Value.AsInterface. Deprecated: Use ListValue.ProtoReflect.Descriptor instead. (*T) GetValues() []*Value (*T) MarshalJSON() ([]byte, error) (*T) ProtoMessage() (*T) ProtoReflect() protoreflect.Message (*T) Reset() (*T) String() string (*T) UnmarshalJSON(b []byte) error *T : google.golang.org/protobuf/reflect/protoreflect.ProtoMessage *T : google.golang.org/protobuf/runtime/protoiface.MessageV1 *T : encoding/json.Marshaler *T : encoding/json.Unmarshaler *T : expvar.Var *T : fmt.Stringer func NewList(v []interface{}) (*ListValue, error) func (*Value).GetListValue() *ListValue func NewListValue(v *ListValue) *Value
`NullValue` is a singleton enumeration to represent the null value for the `Value` type union. The JSON representation for `NullValue` is JSON `null`. ( T) Descriptor() protoreflect.EnumDescriptor ( T) Enum() *NullValue Deprecated: Use NullValue.Descriptor instead. ( T) Number() protoreflect.EnumNumber ( T) String() string ( T) Type() protoreflect.EnumType T : google.golang.org/protobuf/reflect/protoreflect.Enum T : expvar.Var T : fmt.Stringer func NullValue.Enum() *NullValue func (*Value).GetNullValue() NullValue const NullValue_NULL_VALUE const github.com/golang/protobuf/ptypes/struct.NullValue_NULL_VALUE
`Struct` represents a structured data value, consisting of fields which map to dynamically typed values. In some languages, `Struct` might be supported by a native representation. For example, in scripting languages like JS a struct is represented as an object. The details of that representation are described together with the proto support for the language. The JSON representation for `Struct` is JSON object. Unordered map of dynamically typed values. AsMap converts x to a general-purpose Go map. The map values are converted by calling Value.AsInterface. Deprecated: Use Struct.ProtoReflect.Descriptor instead. (*T) GetFields() map[string]*Value (*T) MarshalJSON() ([]byte, error) (*T) ProtoMessage() (*T) ProtoReflect() protoreflect.Message (*T) Reset() (*T) String() string (*T) UnmarshalJSON(b []byte) error *T : google.golang.org/protobuf/reflect/protoreflect.ProtoMessage *T : google.golang.org/protobuf/runtime/protoiface.MessageV1 *T : encoding/json.Marshaler *T : encoding/json.Unmarshaler *T : expvar.Var *T : fmt.Stringer func NewStruct(v map[string]interface{}) (*Struct, error) func (*Value).GetStructValue() *Struct func google.golang.org/genproto/googleapis/api/monitoredres.(*MonitoredResourceMetadata).GetSystemLabels() *Struct func google.golang.org/genproto/googleapis/logging/v2.(*LogEntry).GetJsonPayload() *Struct func NewStructValue(v *Struct) *Value
`Value` represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values. A producer of value is expected to set one of that variants, absence of any variant indicates an error. The JSON representation for `Value` is JSON value. The kind of value. Types that are assignable to Kind: *Value_NullValue *Value_NumberValue *Value_StringValue *Value_BoolValue *Value_StructValue *Value_ListValue AsInterface converts x to a general-purpose Go interface. Calling Value.MarshalJSON and "encoding/json".Marshal on this output produce semantically equivalent JSON (assuming no errors occur). Floating-point values (i.e., "NaN", "Infinity", and "-Infinity") are converted as strings to remain compatible with MarshalJSON. Deprecated: Use Value.ProtoReflect.Descriptor instead. (*T) GetBoolValue() bool (*T) GetKind() isValue_Kind (*T) GetListValue() *ListValue (*T) GetNullValue() NullValue (*T) GetNumberValue() float64 (*T) GetStringValue() string (*T) GetStructValue() *Struct (*T) MarshalJSON() ([]byte, error) (*T) ProtoMessage() (*T) ProtoReflect() protoreflect.Message (*T) Reset() (*T) String() string (*T) UnmarshalJSON(b []byte) error *T : google.golang.org/protobuf/reflect/protoreflect.ProtoMessage *T : google.golang.org/protobuf/runtime/protoiface.MessageV1 *T : encoding/json.Marshaler *T : encoding/json.Unmarshaler *T : expvar.Var *T : fmt.Stringer func NewBoolValue(v bool) *Value func NewListValue(v *ListValue) *Value func NewNullValue() *Value func NewNumberValue(v float64) *Value func NewStringValue(v string) *Value func NewStructValue(v *Struct) *Value func NewValue(v interface{}) (*Value, error) func (*ListValue).GetValues() []*Value func (*Struct).GetFields() map[string]*Value
Represents a boolean value.
Represents a repeated `Value`.
Represents a null value.
Represents a double value.
Represents a string value.
Represents a structured value.
Package-Level Functions (total 12, in which 9 are exported)
NewBoolValue constructs a new boolean Value.
NewList constructs a ListValue from a general-purpose Go slice. The slice elements are converted using NewValue.
NewListValue constructs a new list Value.
NewNullValue constructs a new null Value.
NewNumberValue constructs a new number Value.
NewStringValue constructs a new string Value.
NewStruct constructs a Struct from a general-purpose Go map. The map keys must be valid UTF-8. The map values are converted using NewValue.
NewStructValue constructs a new struct Value.
NewValue constructs a Value from a general-purpose Go interface. ╔════════════════════════╤════════════════════════════════════════════╗ ║ Go type │ Conversion ║ ╠════════════════════════╪════════════════════════════════════════════╣ ║ nil │ stored as NullValue ║ ║ bool │ stored as BoolValue ║ ║ int, int32, int64 │ stored as NumberValue ║ ║ uint, uint32, uint64 │ stored as NumberValue ║ ║ float32, float64 │ stored as NumberValue ║ ║ string │ stored as StringValue; must be valid UTF-8 ║ ║ []byte │ stored as StringValue; base64-encoded ║ ║ map[string]interface{} │ stored as StructValue ║ ║ []interface{} │ stored as ListValue ║ ╚════════════════════════╧════════════════════════════════════════════╝ When converting an int64 or uint64 to a NumberValue, numeric precision loss is possible since they are stored as a float64.
Package-Level Constants (only one, which is exported)