Documentation
¶
Overview ¶
Package sjson provides converters from/to jsonb with some extensions for built-in and `types` types.
See contributing guidelines and documentation for package `types` for details.
Mapping ¶
SJSON uses schema to map values to data types. Schema is stored in the `$s` field of the document and contains information about the fields. A document with schema looks like this:
{
"$s": {
"$k": ["field1", "field2", ...],
"p": {
"field1": {<schema>},
"field2": {<schema>},
...
}
"field1": <json representation>,
"field2": <json representation>,
...
}
Composite types
Alias types package sjson package sjson schema JSON representation
object *types.Document *sjson.documentType {"t":"object", "$s": {"$k":[<keys>], "p":{<properties>}} JSON object
array *types.Array *sjson.arrayType {"t":"array", "i": [<item 1>, <item 2>]} JSON array
Scalar types
Alias types package sjson package sjson schema JSON representation
double float64 *sjson.doubleType {"t":"double"} JSON number
string string *sjson.stringType {"t":"string"} JSON string
binData types.Binary *sjson.binaryType {"t":"binData",
"s":<subtype number>} "<base 64 string>"
objectId types.ObjectID *sjson.objectIDType {"t":"objectId"} "<ObjectID as 24 character hex string>"
bool bool *sjson.boolType {"t":"bool"} JSON true / false values
date time.Time *sjson.dateTimeType {"t":"date"} milliseconds since epoch as JSON number
null types.NullType *sjson.nullType {"t":"null"} JSON null
regex types.Regex *sjson.regexType {"t":"regex",
"o": "<string w/o terminating 0x0>"} "<string w/o terminating 0x0>"
int int32 *sjson.int32Type {"t":"int"} JSON number
timestamp types.Timestamp *sjson.timestampType {"t":"timestamp"} JSON number
long int64 *sjson.int64Type {"t":"long"} JSON number
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTypeOfValue ¶
GetTypeOfValue returns sjson type of supported value. It is used as internal type representation, and shouldn't be used to represent the BSON type.
func Marshal ¶
Marshal encodes given document fields and set its schema in the field $s. Use it when you need to encode a document with schema, for example, when you want to store it in a database.
func MarshalSingleValue ¶
MarshalSingleValue encodes given built-in or types' package value into sjson. Use it when you need to encode a single value, for example in a where clause.
Types ¶
This section is empty.