google/protocol-buffers

Protocol Buffers : Language Guide (proto3) - JSON Mapping

C/H 2018. 9. 7. 08:30

Index

JSON Mapping JSON 매핑

Proto3 supports a canonical encoding in JSON, making it easier to share data between systems. The encoding is described on a type-by-type basis in the table below.
Proto3는 JSON에서 캐논리 인코딩을 지원하므로 시스템 간에 데이터를 더 쉽게 공유할 수 있다. 인코딩은 아래 표에 유형별로 설명되어 있다.

If a value is missing in the JSON-encoded data or if its value is null, it will be interpreted as the appropriate default value when parsed into a protocol buffer. If a field has the default value in the protocol buffer, it will be omitted in the JSON-encoded data by default to save space. An implementation may provide options to emit fields with default values in the JSON-encoded output.
JSON 인코딩 데이터에 값이 없거나 값이 null이면 프로토콜 버퍼로 구문 분석할 때 해당 기본값으로 해석된다. 필드에 프로토콜 버퍼의 기본값이 있으면 기본적으로 JSON 인코딩 데이터에 생략되어 공간을 절약한다. 구현에서는 JSON 인코딩 출력에서 기본값인 필드를 방출하는 옵션을 제공할 수 있다.

proto3 JSONJSON example Notes
message object {"fooBar": v, "g": null, …} Generates JSON objects. Message field names are mapped to lowerCamelCase and become JSON object keys. If the json_name field option is specified, the specified value will be used as the key instead. Parsers accept both the lowerCamelCase name (or the one specified by the json_name option) and the original proto field name. null is an accepted value for all field types and treated as the default value of the corresponding field type.
JSON 개체를 생성한다. 메시지 필드 이름은 lowerCamelCase에 매핑되어 JSON 개체 키가 된다. json_name 필드 옵션이 지정된 경우, 지정한 값이 대신 키로 사용된다. 파서는 하부CamelCase 이름(또는 json_name 옵션으로 지정된 이름)과 원래 양성자 필드 이름을 모두 사용한다. null는 모든 필드 유형에 대해 허용되는 값이며 해당 필드 유형의 기본값으로 취급된다.
enum string "FOO_BAR" The name of the enum value as specified in proto is used. Parsers accept both enum names and integer values.
양성자에 지정된 열거값의 이름이 사용된다. 구문 분석기는 열거형 이름과 정수 값을 모두 허용한다.
map<K,V> object {"k": v, …} All keys are converted to strings.
모든 키가 문자열로 변환된다.
repeated V array [v, …] null is accepted as the empty list [].
null는 빈 목록으로 간주된다.
bool true, false true, false
string string "Hello World!"
bytes base64 string "YWJjMTIzIT8kKiYoKSctPUB+" JSON value will be the data encoded as a string using standard base64 encoding with paddings. Either standard or URL-safe base64 encoding with/without paddings are accepted.
JSON 값은 표준 base64 인코딩과 패딩을 사용하여 문자열로 인코딩된 데이터다. 패드를 사용하거나 사용하지 않고 표준 또는 URL-안전 base64 인코딩을 사용할 수 있다.
int32, fixed32, uint32 number 1, -10, 0 JSON value will be a decimal number. Either numbers or strings are accepted.
JSON 값은 십진수가 된다. 숫자 또는 문자열이 허용된다.
int64, fixed64, uint64 string "1", "-10" JSON value will be a decimal string. Either numbers or strings are accepted.
JSON 값은 십진 문자열이다. 숫자 또는 문자열이 허용된다.
float, double number 1.1, -10.0, 0, "NaN", "Infinity" JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity". Either numbers or strings are accepted. Exponent notation is also accepted.
JSON 값은 숫자 또는 특수 문자열 값 "NaN", "Infinity" 및 "-Infinity" 중 하나가 된다. 숫자 또는 문자열이 허용된다. 지수 표기법도 수락된다.
Any object {"@type": "url", "f": v, … } If the Any contains a value that has a special JSON mapping, it will be converted as follows: {"@type": xxx, "value": yyy}. Otherwise, the value will be converted into a JSON object, and the "@type" field will be inserted to indicate the actual data type.
Any에 특수 JSON 매핑이 포함된 값이 포함되어 있으면 {"@type": xxx, "value": yyy}와 같이 변환된다. 그렇지 않으면 값이 JSON 개체로 변환되고 "@type" 필드가 삽입되어 실제 데이터 유형을 나타낸다.
Timestamp string "1972-01-01T10:00:20.021Z" Uses RFC 3339, where generated output will always be Z-normalized and uses 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted.
RFC 3339를 사용합니다. 여기서 생성된 출력은 항상 Z-정규화되며 0, 3, 6 또는 9개의 소수 자릿수를 사용한다. "Z" 이외의 오프셋도 허용된다.
Duration string "1.000340012s", "1s" Generated output always contains 0, 3, 6, or 9 fractional digits, depending on required precision, followed by the suffix "s". Accepted are any fractional digits (also none) as long as they fit into nano-seconds precision and the suffix "s" is required.
생성된 출력에는 항상 필요한 정밀도에 따라 0, 3, 6 또는 9개의 소수 자릿수가 포함되며 그 뒤에 접미사 "s"가 붙는다. 수락은 나노초 정밀도에 적합하고 접미사 "s"가 필요한 한 모든 부분 숫자(없음)다.
Struct object { … } Any JSON object. See struct.proto.
JSON 객체. structure.proto 참조.
Wrapper types various types 2, "2", "foo", true, "true", null, 0, … Wrappers use the same representation in JSON as the wrapped primitive type, except that null is allowed and preserved during data conversion and transfer.
Wrappers는 데이터 변환 및 전송 중에 null이 허용되고 보존된다는 점을 제외하고는 JSON에서 포장된 원시 유형과 동일한 표현을 사용한다.
FieldMask string "f.fooBar,h" See field_mask.proto.
ListValue array [foo, bar, …]
Value value Any JSON valueJSON 값
NullValue null JSON null

JSON options JSON 옵션

A proto3 JSON implementation may provide the following options:
proto3 JSON 구현은 다음 옵션을 제공할 수 있습니다.

Emit fields with default values: Fields with default values are omitted by default in proto3 JSON output. An implementation may provide an option to override this behavior and output fields with their default values.
기본값이 설정된 필드 표시: 값이 기본값인 필드는 proto3 JSON 출력에서 기본적으로 생략된다. 구현에서는 이 동작 및 출력 필드를 기본값으로 재정의하는 옵션을 제공할 수 있다.

Ignore unknown fields: Proto3 JSON parser should reject unknown fields by default but may provide an option to ignore unknown fields in parsing.
알 수 없는 필드 무시: Proto3 JSON 구문 분석기는 기본적으로 알 수 없는 필드를 거부해야 하지만 구문 분석할 때 알 수 없는 필드를 무시하는 옵션을 제공할 수 있다.

Use proto field name instead of lowerCamelCase name: By default proto3 JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. An implementation may provide an option to use proto field name as the JSON name instead. Proto3 JSON parsers are required to accept both the converted lowerCamelCase name and the proto field name.
lowerCamelCase 이름 대신 protento 필드 이름을 사용합니다. 기본적으로 proto3 JSON 프린터는 필드 이름을 lowerCamelCase로 변환하고 JSON 이름으로 사용한다. 구현에서는 프로토 필드 이름을 대신 JSON 이름으로 사용하는 옵션을 제공할 수 있다. Proto3 JSON 구문 분석기는 변환된 lowerCamelCase 이름과 양성자 필드 이름을 모두 허용해야 한다.

Emit enum values as integers instead of strings: The name of an enum value is used by default in JSON output. An option may be provided to use the numeric value of the enum value instead.
열거값을 문자열이 아닌 정수로 인식합니다. 열거값의 이름은 기본적으로 JSON 출력에서 사용된다. 대신 열거값의 숫자 값을 사용하는 옵션이 제공될 수 있다.

반응형