encoding/serde
Detecting the format of a piece of text and converting JSON, YAML, TOML, XML and CSV into one another.
import encoding.serde
This package reads text in one format, turns it into a Value and writes it out in another. The format names are the short strings json, yaml, toml, xml and csv.
Constants and variables
FormatUnknown
const FormatUnknown: i32 = 0import encoding.serde
func main:
data := `{"name": "salam", "port": 8080, "tags": ["a", "b"]}`
println serde.Detect(data), serde.Detect("a: 1\nb: 2\n"), serde.Detect("<a/>"), serde.Detect("[x]\ny = 1\n"), serde.Detect("a,b\n1,2\n")
println serde.DetectFormat(data) == serde.FormatJSON, serde.FormatUnknown, serde.FormatYAML, serde.FormatTOML, serde.FormatXML, serde.FormatCSV
println serde.Transcode(data, "json", "yaml")
println serde.Transcode(data, "json", "toml")
println serde.Transcode("name,age\nAli,30\n", "csv", "json")
mut ok := false
_ := serde.TranscodeStrict(data, "json", "pdf", ok)
println ok
endFormatJSON
const FormatJSON: i32 = 1The example for this item is shown with the ones above: encoding-serde-Transcode.salam
FormatYAML
const FormatYAML: i32 = 2The example for this item is shown with the ones above: encoding-serde-Transcode.salam
FormatTOML
const FormatTOML: i32 = 3The example for this item is shown with the ones above: encoding-serde-Transcode.salam
FormatXML
const FormatXML: i32 = 4The example for this item is shown with the ones above: encoding-serde-Transcode.salam
FormatCSV
const FormatCSV: i32 = 5The example for this item is shown with the ones above: encoding-serde-Transcode.salam
Functions
DetectFormat
func DetectFormat(text: str): intThe example for this item is shown with the ones above: encoding-serde-Transcode.salam
Detect
func Detect(text: str): strThe example for this item is shown with the ones above: encoding-serde-Transcode.salam
TranscodeStrict
func TranscodeStrict(data: str, from: str, dest: str, ok &: bool): strfrom format to dest; when reading or writing fails, or a format name is wrong, ok becomes false.The example for this item is shown with the ones above: encoding-serde-Transcode.salam
Transcode
func Transcode(data: str, from: str, dest: str): strThe example for this item is shown with the ones above: encoding-serde-Transcode.salam