1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
2022-05-26 15:27:54 +03:00
..
json_decode_test.v fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00
json_decode_with_encode_arg_test.v fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00
json_decode_with_optional_arg_test.v fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00
json_decode_with_sumtype_test.v fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00
json_primitives.v json: fix struct field default value support (#14304) 2022-05-20 11:22:17 +03:00
json_test.v tests: make json_test.v less noisy, to see errors easier 2022-05-26 15:27:54 +03:00
README.md fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00

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
}