package core:encoding/json
⌘K
Ctrl+K
or
/
Index
Constants (1)
Variables (0)
This section is empty.
Procedures (41)
- advance_token
- allow_token
- clone_string
- clone_value
- destroy_value
- expect_token
- get_token
- is_valid
- is_valid_number
- is_valid_string_literal
- make_parser
- make_parser_from_string
- make_tokenizer
- marshal
- marshal_to_builder
- marshal_to_writer
- next_rune
- opt_write_end
- opt_write_indentation
- opt_write_iteration
- opt_write_key
- opt_write_start
- parse
- parse_array
- parse_colon
- parse_comma
- parse_object
- parse_object_body
- parse_object_key
- parse_string
- parse_value
- token_end_pos
- unmarshal
- unmarshal_any
- unmarshal_string
- unquote_string
- validate_array
- validate_object
- validate_object_body
- validate_object_key
- validate_value
Procedure Groups (0)
This section is empty.
Types
Error ¶
Error :: enum int { None, EOF, // Not necessarily an error // Tokenizing Errors Illegal_Character, Invalid_Number, String_Not_Terminated, Invalid_String, // Parsing Errors Unexpected_Token, Expected_String_For_Object_Key, Duplicate_Object_Key, Expected_Colon_After_Key, // Allocating Errors Invalid_Allocator, Out_Of_Memory, }
Related Procedures With Returns
Marshal_Data_Error ¶
Marshal_Data_Error :: enum int { None, Unsupported_Type, }
Marshal_Error ¶
Marshal_Error :: union { Marshal_Data_Error, io.Error, }
Related Procedures With Returns
Marshal_Options ¶
Marshal_Options :: struct { // output based on spec spec: Specification, // Use line breaks & tabs/spaces pretty: bool, // Use spaces for indentation instead of tabs use_spaces: bool, // Given use_spaces true, use this many spaces per indent level. 0 means 4 spaces. spaces: int, // Output uint as hex in JSON5 & MJSON write_uint_as_hex: bool, // If spec is MJSON and this is true, then keys will be quoted. // // WARNING: If your keys contain whitespace and this is false, then the // output will be bad. mjson_keys_use_quotes: bool, // If spec is MJSON and this is true, then use '=' as delimiter between // keys and values, otherwise ':' is used. mjson_keys_use_equal_sign: bool, // When outputting a map, sort the output by key. // // NOTE: This will temp allocate and sort a list for each map. sort_maps_by_key: bool, // Output enum value's name instead of its underlying value. // // NOTE: If a name isn't found it'll use the underlying value. use_enum_names: bool, // Internal state indentation: int, mjson_skipped_first_braces_start: bool, mjson_skipped_first_braces_end: bool, }
careful with MJSON maps & non quotes usage as keys with whitespace will lead to bad results
Related Procedures With Parameters
Object ¶
Related Procedures With Returns
Parser ¶
Parser :: struct { tok: Tokenizer, prev_token: Token, curr_token: Token, spec: Specification, allocator: runtime.Allocator, parse_integers: bool, }
Related Procedures With Parameters
- advance_token
- allow_token
- expect_token
- parse_array
- parse_colon
- parse_comma
- parse_object
- parse_object_body
- parse_object_key
- parse_value
- validate_array
- validate_object
- validate_object_body
- validate_object_key
- validate_value
Related Procedures With Returns
Pos ¶
Related Procedures With Returns
Specification ¶
Specification :: enum int { JSON, JSON5, // https://json5.org/ SJSON, // https://bitsquid.blogspot.com/2009/10/simplified-json-notation.html Bitsquid = 2, MJSON = 2, }
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 =
Related Procedures With Parameters
- is_valid
- is_valid_number
- is_valid_string_literal
- make_parser
- make_parser_from_string
- make_tokenizer
- parse
- parse_string
- unmarshal
- unmarshal_any
- unmarshal_string
- unquote_string
Related Constants
Token ¶
Token :: struct { using pos: Pos, kind: Token_Kind, text: string, }
Related Procedures With Parameters
Related Procedures With Returns
Token_Kind ¶
Token_Kind :: enum int { Invalid, EOF, Null, False, True, Infinity, NaN, Ident, Integer, Float, String, Colon, Comma, Open_Brace, Close_Brace, Open_Bracket, Close_Bracket, }
Related Procedures With Parameters
Tokenizer ¶
Tokenizer :: struct { using pos: Pos, data: string, r: rune, // current rune w: int, // current rune width in bytes curr_line_offset: int, spec: Specification, parse_integers: bool, insert_comma: bool, }
Related Procedures With Parameters
Related Procedures With Returns
Unmarshal_Data_Error ¶
Unmarshal_Data_Error :: enum int { Invalid_Data, Invalid_Parameter, Non_Pointer_Parameter, Multiple_Use_Field, }
Unmarshal_Error ¶
Unmarshal_Error :: union { Error, Unmarshal_Data_Error, Unsupported_Type_Error, }
Related Procedures With Returns
Constants
DEFAULT_SPECIFICATION ¶
DEFAULT_SPECIFICATION :: Specification.JSON5
Variables
This section is empty.
Procedures
allow_token ¶
allow_token :: proc(p: ^Parser, kind: Token_Kind) -> bool {…}
clone_string ¶
clone_string :: proc(s: string, allocator: runtime.Allocator, loc := #caller_location) -> (str: string, err: Error) {…}
clone_value ¶
clone_value :: proc(value: Value, allocator := context.allocator) -> Value {…}
destroy_value ¶
destroy_value :: proc(value: Value, allocator := context.allocator, loc := #caller_location) {…}
expect_token ¶
expect_token :: proc(p: ^Parser, kind: Token_Kind) -> Error {…}
is_valid ¶
is_valid :: proc(data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false) -> bool {…}
NOTE(bill): is_valid will not check for duplicate keys
is_valid_number ¶
is_valid_number :: proc(str: string, spec: Specification) -> bool {…}
is_valid_string_literal ¶
is_valid_string_literal :: proc(str: string, spec: Specification) -> bool {…}
make_parser ¶
make_parser :: proc(data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> Parser {…}
make_parser_from_string ¶
make_parser_from_string :: proc(data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> Parser {…}
make_tokenizer ¶
make_tokenizer :: proc(data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false) -> Tokenizer {…}
marshal ¶
marshal :: proc(v: any, opt: Marshal_Options = {}, allocator := context.allocator, loc := #caller_location) -> (data: []u8, err: Marshal_Error) {…}
marshal_to_builder ¶
marshal_to_builder :: proc(b: ^strings.Builder, v: any, opt: ^Marshal_Options) -> Marshal_Error {…}
marshal_to_writer ¶
marshal_to_writer :: proc(w: io.Stream, v: any, opt: ^Marshal_Options) -> (err: Marshal_Error) {…}
opt_write_end ¶
opt_write_end :: proc(w: io.Stream, opt: ^Marshal_Options, c: u8) -> (err: io.Error) {…}
decrease indent, write spacing and insert end byte
opt_write_indentation ¶
opt_write_indentation :: proc(w: io.Stream, opt: ^Marshal_Options) -> (err: io.Error) {…}
writes current indentation level based on options
opt_write_iteration ¶
opt_write_iteration :: proc(w: io.Stream, opt: ^Marshal_Options, first_iteration: bool) -> (err: io.Error) {…}
insert comma separation and write indentations
opt_write_key ¶
opt_write_key :: proc(w: io.Stream, opt: ^Marshal_Options, name: string) -> (err: io.Error) {…}
write key as quoted string or with optional quotes in mjson
opt_write_start ¶
opt_write_start :: proc(w: io.Stream, opt: ^Marshal_Options, c: u8) -> (err: io.Error) {…}
insert start byte and increase indentation on pretty
parse ¶
parse :: proc(data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator, loc := #caller_location) -> (Value, Error) {…}
parse_array ¶
parse_array :: proc(p: ^Parser, loc := #caller_location) -> (value: Value, err: Error) {…}
parse_object ¶
parse_object :: proc(p: ^Parser, loc := #caller_location) -> (value: Value, err: Error) {…}
parse_object_body ¶
parse_object_body :: proc(p: ^Parser, end_token: Token_Kind, loc := #caller_location) -> (obj: Object, err: Error) {…}
parse_object_key ¶
parse_object_key :: proc(p: ^Parser, key_allocator: runtime.Allocator, loc := #caller_location) -> (key: string, err: Error) {…}
parse_string ¶
parse_string :: proc(data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator, loc := #caller_location) -> (Value, Error) {…}
parse_value ¶
parse_value :: proc(p: ^Parser, loc := #caller_location) -> (value: Value, err: Error) {…}
unmarshal ¶
unmarshal :: proc(data: []u8, ptr: ^$T, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}
unmarshal_any ¶
unmarshal_any :: proc(data: []u8, v: any, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}
unmarshal_string ¶
unmarshal_string :: proc(data: string, ptr: ^$T, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}
unquote_string ¶
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
validate_object_body ¶
validate_object_body :: proc(p: ^Parser, end_token: Token_Kind) -> bool {…}
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2024-10 (vendor "odin") Windows_amd64 @ 2024-10-05 21:10:06.110346700 +0000 UTC