1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
Alexander Medvednikov af73e195da net: byte fixes
2022-04-15 15:55:39 +03:00
..
json_decode_test.v json: return errors with more context, on failed json.decode() calls. 2022-04-05 12:06:08 +03:00
json_decode_with_encode_arg_test.v cgen: fix json decode with optional argument (fix #13943) (#13958) 2022-04-06 19:34:22 +03:00
json_decode_with_optional_arg_test.v cgen: fix optional struct declarations for empty structs (#13970) 2022-04-08 14:51:37 +03:00
json_decode_with_sumtype_test.v json: fix json decode with sumtype of multi array type (#14035) 2022-04-14 15:36:24 +03:00
json_primitives.v net: byte fixes 2022-04-15 15:55:39 +03:00
json_test.v builtin: change IError msg and code to methods + fix vlib, add a deprecation notice for the old usages (#13041) 2022-02-11 15:52:33 +02:00
README.md docs: adding skeleton README.md files for all vlib modules (#13034) 2022-01-05 18:06:08 +02: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
}