1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
2023-05-02 16:41:32 +02:00
..
cjson all: 2023 copyright 2023-03-28 22:55:57 +02:00
json_alias_test.v json: fix json.decode with map alias (#17925) 2023-04-10 19:50:35 +03:00
json_decode_test.v json: skip via the "-" attribute 2023-05-02 16:41:32 +02: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 all: replace generic <> with [] - part 2 (#16536) 2022-11-26 18:23:26 +02:00
json_decode_with_option_arg_test.v all: change optional to option (#16914) 2023-01-09 09:36:45 +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_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_map_test.v json: fix -cstrict build + optional map (#18014) 2023-04-22 10:55:25 +03:00
json_encode_primite_test.v json: allow decode/encode of alias to primitive type (#18003) 2023-04-21 19:39:40 +03:00
json_encode_struct_with_option_field_test.v cgen: fix json encoding of structs with option fields (skip the fields with a value of none) (#16916) 2023-01-09 15:33:08 +02:00
json_encode_sumtype_test.v json: fix option sumtype with int types (#18013) 2023-04-22 10:58:01 +03:00
json_encode_with_mut_test.v json: fix ptr field access (#17690) 2023-03-18 14:47:40 +02:00
json_encode_with_ptr_test.v json: support field &Type (#17655) 2023-03-16 21:15:14 +02:00
json_generic_array_test.v json: fix encode/decode fixed array (#17887) 2023-04-06 01:15:23 +03:00
json_omitempty_test.v json: fix [omitempty] with string (#17813) 2023-03-30 23:09:47 +03:00
json_omitempty_types_test.v json: fix omitempty for alias, struct, sumtype, array and map (#18012) 2023-04-22 10:58:21 +03:00
json_option_struct_test.v json: fix json with option struct (#17942) 2023-04-13 08:17:40 +02:00
json_option_test.v json: fix json decode/encode with option type (#17393) 2023-03-10 10:49:26 +02:00
json_primitives.v all: 2023 copyright 2023-03-28 22:55:57 +02:00
json_raw_test.v json: fix [raw] for option string (#17899) 2023-04-06 18:26:17 +03: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 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
}