1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
2022-11-20 11:18:14 +02:00
..
cjson json.cjson: add a test case for more complex json object construction 2022-09-21 17:22:42 +03:00
json_decode_test.v db, json, time, term: change optional to result (#16201) 2022-10-26 11:26:28 +03:00
json_decode_with_encode_arg_test.v db, json, time, term: change optional to result (#16201) 2022-10-26 11:26:28 +03:00
json_decode_with_generic_test.v db, json, time, term: change optional to result (#16201) 2022-10-26 11:26:28 +03:00
json_decode_with_optional_arg_test.v vfmt: change all '$expr' to '${expr}' (#16428) 2022-11-15 16:53:13 +03:00
json_decode_with_sumtype_test.v db, json, time, term: change optional to result (#16201) 2022-10-26 11:26:28 +03:00
json_primitives.v db, json, time, term: change optional to result (#16201) 2022-10-26 11:26:28 +03:00
json_test.v builtin, cgen: support FieldData.unaliased_typ, use it for generalising x.json2 (able to encode type aliased struct fields) (#16469) 2022-11-20 11:18:14 +02:00
README.md vfmt: change all '$expr' to '${expr}' (#16428) 2022-11-15 16:53:13 +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
}