1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
2023-03-30 23:09:47 +03:00
..
cjson all: 2023 copyright 2023-03-28 22:55:57 +02:00
json_decode_test.v
json_decode_with_encode_arg_test.v
json_decode_with_generic_test.v
json_decode_with_option_arg_test.v
json_decode_with_sumtype_test.v
json_encode_enum_test.v json: make enums work with json encode+decode (serialised as string names by default; the old integer one is supported too, using [json_as_number]) (#17696) 2023-03-22 10:33:32 +02:00
json_encode_struct_with_option_field_test.v
json_encode_with_mut_test.v
json_encode_with_ptr_test.v
json_omitempty_test.v json: fix [omitempty] with string (#17813) 2023-03-30 23:09:47 +03:00
json_option_test.v
json_primitives.v all: 2023 copyright 2023-03-28 22:55:57 +02:00
json_struct_option_test.v json: fix decode option string (#17812) 2023-03-29 18:45:41 +02:00
json_test.v json: make enums work with json encode+decode (serialised as string names by default; the old integer one is supported too, using [json_as_number]) (#17696) 2023-03-22 10:33:32 +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
}