| 1 | module json2 |
| 2 | |
| 3 | import time |
| 4 | |
| 5 | @[markused] |
| 6 | const any_time_type_marker = time.Time{} |
| 7 | |
| 8 | // Any is a sum type that lists the possible types to be decoded and used. |
| 9 | // `Any` priority order for numbers: floats -> signed integers -> unsigned integers |
| 10 | // `Any` priority order for strings: string -> time.Time |
| 11 | |
| 12 | @[markused] |
| 13 | pub type Any = []Any |
| 14 | | bool |
| 15 | | f64 |
| 16 | | f32 |
| 17 | | i64 |
| 18 | | int |
| 19 | | i32 |
| 20 | | i16 |
| 21 | | i8 |
| 22 | | map[string]Any |
| 23 | | string |
| 24 | | time.Time |
| 25 | | u64 |
| 26 | | u32 |
| 27 | | u16 |
| 28 | | u8 |
| 29 | | Null |
| 30 | |
| 31 | // Null is a simple representation of the `null` value in JSON. |
| 32 | pub struct Null {} |
| 33 | |
| 34 | // null is an instance of the Null type, to ease comparisons with it. |
| 35 | pub const null = Null{} |
| 36 | |
| 37 | // from_json_null implements a custom decoder for json2 |
| 38 | @[markused] |
| 39 | pub fn (mut n Null) from_json_null() {} |
| 40 | |
| 41 | // to_json implements a custom encoder for json2 |
| 42 | pub fn (n Null) to_json() string { |
| 43 | return 'null' |
| 44 | } |
| 45 | |
| 46 | // ValueKind enumerates the kinds of possible values of the Any sumtype. |
| 47 | enum ValueKind { |
| 48 | array |
| 49 | object |
| 50 | string |
| 51 | number |
| 52 | boolean |
| 53 | null |
| 54 | } |
| 55 | |