package core:encoding/json

Types

Array ¶

Array :: distinct [dynamic]Value

Boolean ¶

Boolean :: bool

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, 
}

Float ¶

Float :: f64

Integer ¶

Integer :: i64

Marshal_Data_Error ¶

Marshal_Data_Error :: enum int {
	None, 
	Unsupported_Type, 
}

Marshal_Error ¶

Marshal_Error :: union {
	Marshal_Data_Error, 
	io.Error, 
}

Marshal_Options ¶

Marshal_Options :: struct {
	// output based on spec
	spec:                             Specification,
	// use line breaks & tab|spaces
	pretty:                           bool,
	// spacing
	use_spaces:                       bool,
	spaces:                           int,
	// state
	indentation:                      int,
	// option to output uint in JSON5 & MJSON
	write_uint_as_hex:                bool,
	// mjson output options
	mjson_keys_use_quotes:            bool,
	mjson_keys_use_equal_sign:        bool,
	// mjson state
	mjson_skipped_first_braces_start: bool,
	mjson_skipped_first_braces_end:   bool,
}
 

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

Null ¶

Null :: distinct rawptr

Object ¶

Object :: distinct map[string]Value

Parser ¶

Parser :: struct {
	tok:            Tokenizer,
	prev_token:     Token,
	curr_token:     Token,
	spec:           Specification,
	allocator:      runtime.Allocator,
	parse_integers: bool,
}

Pos ¶

Pos :: struct {
	offset: int,
	line:   int,
	column: int,
}

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 =

String ¶

String :: string

Token ¶

Token :: struct {
	pos:  Pos,
	kind: Token_Kind,
	text: string,
}

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, 
}

Tokenizer ¶

Tokenizer :: struct {
	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,
}

Unmarshal_Data_Error ¶

Unmarshal_Data_Error :: enum int {
	Invalid_Data, 
	Invalid_Parameter, 
	Non_Pointer_Parameter, 
	Multiple_Use_Field, 
}

Unsupported_Type_Error ¶

Unsupported_Type_Error :: struct {
	id:    typeid,
	token: Token,
}

Value ¶

Value :: union {
	Null, 
	i64, 
	f64, 
	bool, 
	string, 
	Array, 
	Object, 
}

Constants

DEFAULT_SPECIFICATION ¶

DEFAULT_SPECIFICATION :: Specification.JSON5

Variables

This section is empty.

Procedures

advance_token ¶

advance_token :: proc "odin" (p: ^Parser) -> (Token, Error) {…}

allow_token ¶

allow_token :: proc "odin" (p: ^Parser, kind: Token_Kind) -> bool {…}

clone_string ¶

clone_string :: proc "odin" (s: string, allocator: runtime.Allocator) -> (str: string, err: Error) {…}

destroy_value ¶

destroy_value :: proc "odin" (value: Value) {…}

expect_token ¶

expect_token :: proc "odin" (p: ^Parser, kind: Token_Kind) -> Error {…}

get_token ¶

get_token :: proc "odin" (t: ^Tokenizer) -> (token: Token, err: Error) {…}

is_valid ¶

is_valid :: proc "odin" (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 "odin" (str: string, spec: Specification) -> bool {…}

is_valid_string_literal ¶

is_valid_string_literal :: proc "odin" (str: string, spec: Specification) -> bool {…}

make_parser ¶

make_parser :: proc "odin" (data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> Parser {…}

make_parser_from_string ¶

make_parser_from_string :: proc "odin" (data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> Parser {…}

make_tokenizer ¶

make_tokenizer :: proc "odin" (data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false) -> Tokenizer {…}

marshal ¶

marshal :: proc "odin" (v: any, opt: Marshal_Options = {}, allocator := context.allocator) -> (data: []u8, err: Marshal_Error) {…}

marshal_to_builder ¶

marshal_to_builder :: proc "odin" (b: ^strings.Builder, v: any, opt: ^Marshal_Options) -> Marshal_Error {…}

marshal_to_writer ¶

marshal_to_writer :: proc "odin" (w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: Marshal_Error) {…}

next_rune ¶

next_rune :: proc "odin" (t: ^Tokenizer) -> rune {…}

opt_write_end ¶

opt_write_end :: proc "odin" (w: io.Writer, opt: ^Marshal_Options, c: u8) -> (err: io.Error) {…}
 

decrease indent, write spacing and insert end byte

opt_write_indentation ¶

opt_write_indentation :: proc "odin" (w: io.Writer, opt: ^Marshal_Options) -> (err: io.Error) {…}
 

writes current indentation level based on options

opt_write_iteration ¶

opt_write_iteration :: proc "odin" (w: io.Writer, opt: ^Marshal_Options, iteration: int) -> (err: io.Error) {…}
 

insert comma seperation and write indentations

opt_write_key ¶

opt_write_key :: proc "odin" (w: io.Writer, 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 "odin" (w: io.Writer, opt: ^Marshal_Options, c: u8) -> (err: io.Error) {…}
 

insert start byte and increase indentation on pretty

parse ¶

parse :: proc "odin" (data: []u8, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> (Value, Error) {…}

parse_array ¶

parse_array :: proc "odin" (p: ^Parser) -> (value: Value, err: Error) {…}

parse_colon ¶

parse_colon :: proc "odin" (p: ^Parser) -> (err: Error) {…}

parse_comma ¶

parse_comma :: proc "odin" (p: ^Parser) -> (do_break: bool) {…}

parse_object ¶

parse_object :: proc "odin" (p: ^Parser) -> (value: Value, err: Error) {…}

parse_object_body ¶

parse_object_body :: proc "odin" (p: ^Parser, end_token: Token_Kind) -> (obj: Object, err: Error) {…}

parse_object_key ¶

parse_object_key :: proc "odin" (p: ^Parser, key_allocator: runtime.Allocator) -> (key: string, err: Error) {…}

parse_string ¶

parse_string :: proc "odin" (data: string, spec: Specification = DEFAULT_SPECIFICATION, parse_integers: bool = false, allocator := context.allocator) -> (Value, Error) {…}

parse_value ¶

parse_value :: proc "odin" (p: ^Parser) -> (value: Value, err: Error) {…}

token_end_pos ¶

token_end_pos :: proc "odin" (tok: Token) -> Pos {…}

unmarshal ¶

unmarshal :: proc "odin" (data: []u8, ptr: ^$, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}

unmarshal_any ¶

unmarshal_any :: proc "odin" (data: []u8, v: any, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}

unmarshal_string ¶

unmarshal_string :: proc "odin" (data: string, ptr: ^$, spec: Specification = DEFAULT_SPECIFICATION, allocator := context.allocator) -> Unmarshal_Error {…}

unquote_string ¶

unquote_string :: proc "odin" (token: Token, spec: Specification, allocator := context.allocator) -> (value: string, err: Error) {…}
 

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

validate_array ¶

validate_array :: proc "odin" (p: ^Parser) -> (do_break: bool) {…}

validate_object ¶

validate_object :: proc "odin" (p: ^Parser) -> (do_break: bool) {…}

validate_object_body ¶

validate_object_body :: proc "odin" (p: ^Parser, kind: Token_Kind) -> bool {…}

validate_object_key ¶

validate_object_key :: proc "odin" (p: ^Parser) -> (do_break: bool) {…}

validate_value ¶

validate_value :: proc "odin" (p: ^Parser) -> (do_break: bool) {…}

Procedure Groups

This section is empty.

Source Files

Generation Information

Generated with odin version dev-2022-10 (vendor "odin") Windows_amd64 @ 2022-10-05 21:11:47.351810300 +0000 UTC