Encoding and decoding JSON in strict `JSON`, [[ JSON5 ; https://json5.org/ ]] and [[ BitSquid ; https://bitsquid.blogspot.com/2009/10/simplified-json-notation.html ]] variants. Using one of these `Specification`s. JSON strict JSON JSON5 pure superset of JSON and valid JavaScript https://json5.org/ * Object keys may be an ECMAScript 5.1 IdentifierName. * Objects may have a single trailing comma. * Arrays may have a single trailing comma. * Strings may be single quoted. * Strings may span multiple lines by escaping new line characters. * Strings may include character escapes * Numbers may be hexadecimal. * Numbers may have a leading or trailing decimal point. * Numbers may be IEEE 754 positive infinity, negative infinity, and NaN. * Numbers may begin with an explicit plus sign. * Single and multi-line comments are allowed. * Additional white space characters are allowed. MJSON pure superset of JSON5, may not be valid JavaScript https://bitsquid.blogspot.com/2009/10/simplified-json-notation.html * All the same features as JSON5 plus extras. * Assume an object definition at the root level (no need to surround entire file with { } ). * Commas are optional, using comma insertion rules with newlines. * Quotes around object keys are optional if the keys are valid identifiers. * : can be replaced with =

Collection Info

View Source
Collection
core
Path
encoding/json
Entries
72

Source Files

Constants

1

DEFAULT_SPECIFICATION #

Source
DEFAULT_SPECIFICATION :: Specification.JSON5

Types

25

Marshal_Options #

Source
Marshal_Options :: Marshal_Options

careful with MJSON maps & non quotes usage as keys with whitespace will lead to bad results

Procedures

46

destroy_value #

Source
destroy_value :: proc(value: Value, allocator := context.allocator, loc := #caller_location) {…}

is_valid #

Source
is_valid :: proc(data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false) -> bool {…}

NOTE(bill): is_valid will not check for duplicate keys

register_user_marshaler #

Source
register_user_marshaler :: proc(id: typeid, marshaler: User_Marshaler) -> Register_User_Marshaler_Error {…}

Registers a user-defined marshaler for a specific typeid Inputs: - id: The typeid of the custom type. - formatter: The User_Marshaler function for the custom type. Returns: A Register_User_Marshaler_Error value indicating the success or failure of the operation. WARNING: set_user_marshalers must be called before using this procedure.

register_user_unmarshaler #

Source
register_user_unmarshaler :: proc(id: typeid, unmarshaler: User_Unmarshaler) -> Register_User_Unmarshaler_Error {…}

Registers a user-defined unmarshaler for a specific `typeid`. WARNING: set_user_unmarshalers must be called before using this procedure. Inputs: - id: The `typeid` of the custom type. - unmarshaler: The `User_Unmarshaler` function for the custom type. Example: import "core:fmt" import "core:encoding/json" import "core:strconv" // Custom Unmarshaler for `int` some_unmarshaler :: proc(p: ^json.Parser, v: any) -> json.Unmarshal_Error { token := p.curr_token.text i, ok := strconv.parse_i64_of_base(token, 2) if !ok { return .Invalid_Data } (^int)(v.data)^ = int(i) json.advance_token(p) return nil } register_user_unmarshaler_example :: proc() { // Ensure the `json._user_unmarshalers` map is initialized. json.set_user_unmarshalers(new(map[typeid]json.User_Unmarshaler)) reg_err := json.register_user_unmarshaler(typeid_of(int), some_unmarshaler) assert(reg_err == .None) data := `{"value":101010}` SomeType :: struct { value: int, } y: SomeType unmarshal_err := json.unmarshal(transmute([]byte)data, &y) fmt.println(y, unmarshal_err) } Output: SomeType{value = 42} nil

set_user_marshalers #

Source
set_user_marshalers :: proc(m: ^map[typeid]User_Marshaler) {…}

Sets user-defined marshalers for custom json marshaling of specific types Inputs: - m: A pointer to a map of typeids to User_Marshaler procs. NOTE: Must be called before using register_user_marshaler.

set_user_unmarshalers #

Source
set_user_unmarshalers :: proc(m: ^map[typeid]User_Unmarshaler) {…}

Sets user-defined unmarshalers for custom json unmarshaling of specific types Inputs: - m: A pointer to a map of typeids to User_Unmarshaler procs. NOTE: Must be called before using `register_user_unmarshaler`.

unquote_string #

Source
unquote_string :: proc(token: Token, spec: Specification, allocator := context.allocator, loc := #caller_location) -> (value: string, err: Error) {…}

IMPORTANT NOTE(bill): unquote_string assumes a mostly valid string