1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json
2023-03-10 10:49:26 +02:00
..
cjson
json_decode_test.v
json_decode_with_encode_arg_test.v
json_decode_with_generic_test.v
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
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_option_test.v json: fix json decode/encode with option type (#17393) 2023-03-10 10:49:26 +02:00
json_primitives.v
json_test.v
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
}