xref: /inferno-os/module/json.m (revision ee1a8f4a2601560b3563fa4bd92075ac2883fb06)
1JSON: module
2{
3	PATH:	con "/dis/lib/json.dis";
4
5	JValue: adt {
6		pick{
7		Object =>
8			mem: cyclic list of (string, ref JValue);
9		Array =>
10			a: cyclic array of ref JValue;
11		String =>
12			s: string;
13		Int =>
14			value:	big;	# could use IPint?	# just use Number (as string)
15		Real =>
16			value:	real;
17		True or False or Null =>
18		}
19
20		isarray:	fn(o: self ref JValue): int;
21		isfalse:	fn(o: self ref JValue): int;
22		isint:		fn(o: self ref JValue): int;
23		isnull:	fn(o: self ref JValue): int;
24		isnumber: fn(o: self ref JValue): int;
25		isobject:	fn(o: self ref JValue): int;
26		isreal:	fn(o: self ref JValue): int;
27		isstring:	fn(o: self ref JValue): int;
28		istrue:	fn(o: self ref JValue): int;
29		copy:	fn(o: self ref JValue): ref JValue;
30		eq:	fn(a: self ref JValue, b: ref JValue): int;
31		get:	fn(a: self ref JValue, n: string): ref JValue;
32		set:	fn(a: self ref JValue, mem: string, value: ref JValue);
33		text:	fn(a: self ref JValue): string;
34	};
35
36	init:	fn(bufio: Bufio);
37	readjson:	fn(buf: ref Bufio->Iobuf): (ref JValue, string);
38	writejson:	fn(buf: ref Bufio->Iobuf, val: ref JValue): int;
39
40	# shorthand?
41	jvarray:	fn(a: array of ref JValue): ref JValue.Array;
42	jvbig:	fn(b: big): ref JValue.Int;
43	jvfalse:	fn(): ref JValue.False;
44	jvint:		fn(i: int): ref JValue.Int;
45	jvnull:	fn(): ref JValue.Null;
46	jvobject:	fn(m: list of (string, ref JValue)): ref JValue.Object;
47	jvreal:	fn(r: real): ref JValue.Real;
48	jvstring:	fn(s: string): ref JValue.String;
49	jvtrue:	fn(): ref JValue.True;
50};
51