v/vlib/json
Delyan Angelov 9ebd56caa7
cgen,json: bugfix for json.decode; now `[skip]` fields are initialised
2022-01-22 19:29:38 +02:00
..
README.md docs: adding skeleton README.md files for all vlib modules (#13034) 2022-01-05 18:06:08 +02:00
json_decode_test.v cgen,json: bugfix for json.decode; now `[skip]` fields are initialised 2022-01-22 19:29:38 +02:00
json_primitives.v all: update copyright year 2022-01-04 12:21:12 +03:00
json_test.v json: fix error for json encoding sumtype value (#13248) 2022-01-22 17:55:19 +02:00

README.md

Description:

json provides encoding/decoding of V data structures to/from JSON.

Examples:

import json

enum JobTitle {
	manager
	executive
	worker
}

struct Employee {
	name   string
	age    int
	salary f32
	title  JobTitle
}

fn main() {
	x := Employee{'Peter', 28, 95000.5, .worker}
	println(x)
	//
	s := json.encode(x)
	println('Employee x: $s')
	assert s == '{"name":"Peter","age":28,"salary":95000.5,"title":2}'
	//
	y := json.decode(Employee, s) ?
	//
	println(y)
	assert y == x
}