If you want to update this page or add new content, please submit a pull request to the Homepage.

YSON

YSON(Yorkie Structured Object Notation) is a structured data format used by Yorkie to represent documents. It is similar to JSON but extends it with additional data types optimized for collaborative editing.

Data Types

YSON supports standard JSON types and adds specialized types for collaborative applications. Each YSON type has specific use cases and representation formats:

TypeDescriptionFormat ExampleUse Case
StringUTF-8 encoded text"value1"Text content
NumberStandard numeric value42.5Generic numeric values
BooleanTrue or falsetrueFlags and boolean states
NullNull valuenullAbsent or undefined values
ObjectCollection of key-value pairs{"key": "value"}Structured data
ArrayOrdered list of values[1, 2, 3]Sequential collections
Int32-bit integerInt(42)Precise integer values
Long64-bit integerLong(64)Large integer values
DateISO 8601 timestampDate("2025-01-02T15:04:05.058Z")Time values
BinDataBinary data with Base64 encodingBinData("AQID")Binary content
CounterConcurrent counterCounter(Int(10))Collaborative counting
TextList-based Rich TextText({"type":"p",...})List-based Rich Text Editor, e.g) Quill
TreeTree-based Rich TextTree({"type":"p",...})Tree-based Rich Text Editor

Custom Types Details

Int and Long

YSON provides explicit integer types to ensure consistent handling across platforms:

  • Int(number): A 32-bit integer type (-2,147,483,648 to 2,147,483,647)
  • Long(number): A 64-bit integer type for larger numbers

These types help ensure that numeric values are interpreted consistently when sharing documents across different programming languages.

Date

YSON Date represents a timestamp value in ISO 8601 format:

Date("2025-01-02T15:04:05.058Z")

Dates in YSON are stored as strings in ISO format for consistent representation across systems.

BinData

Binary data in YSON is represented using Base64 encoding:

BinData("AQID") // Base64 encoded binary data

This allows binary content to be safely represented and transmitted as text.

Counter

Counter type is specifically designed for collaborative counting operations where multiple users might modify a numeric value concurrently:

Counter(Int(10)) // A counter with initial value of 10

Using Counter instead of a regular number prevents conflicts when multiple users increment or decrement values simultaneously.

Text

The Text type is designed for rich text editing, allowing for complex formatting and attributes:

Text([{"val":"Hello","attrs":{"color":"red"}},{"val":"World","attrs":{"color":"blue"}}])

This structure allows for a list of text segments, each with its own attributes, enabling rich text editing capabilities.

Tree

The Tree type provides a specialized structure for representing hierarchical data, particularly useful for rich text editing:

Tree({"type":"p","children":[{"type":"text","value":"Tree in object"}]})

This structure allows for a tree-based representation of rich text, where each node can have its own type and attributes.

Example Document

{
"str": "value1", // Standard string
"num": 42, // Standard number(float64)
"int": Int(42), // 32-bit integer
"long": Long(64), // 64-bit integer
"null": null, // Standard null
"bool": true, // Standard boolean
"bytes": BinData("AQID"), // Binary data (Base64)
"date": Date("2025-01-02T15:04:05.058Z"), // Date and time
"counter": Counter(Int(10)), // Counter with integer value
"text": Text([{"val":"Hello","attrs":{"color":"red"}},{"val":"World","attrs":{"color":"blue"}}]), // List-based Rich Text
"tree": Tree({"type":"p","attrs":{"align":"center"},"children":[{"type":"text","value":"Hello World"}]}) // Tree-based Rich Text
}