21. Boost package for JSON

The JSON boost module implements collection of helper macros and functions to accompany JSON.

All functions and symbols are in “json_boost” module, use require to get access to it.

require daslib/json_boost

21.1. Structures

JsonFieldState
Fields
  • argName : string - name of the field in JSON

  • enumAsInt : bool - whether to parse enum as integer

  • unescape : bool - whether to unescape strings

  • embed : bool - whether to embed the field

  • optional : bool - whether the field is optional

21.2. Reader macros

json
This macro implements embedding of the JSON object into the program::

var jsv = %json~ {

“name”: “main_window”, “value”: 500, “size”: [1,2,3]

} %%

21.3. Variant macros

better_json

This macro is used to implement is json_value and as json_value runtime checks. It essencially substitutes value as name with value.value as name and value is name with value.value is name.

21.4. Value conversion

from_JV(v: JsonValue const?; ent: auto(EnumT); defV: EnumT = EnumT()) : EnumT()

Parse a JSON value and return the corresponding native value.

Arguments
  • v : JsonValue ?

  • ent : auto(EnumT)

  • defV : EnumT

from_JV(v: JsonValue const?; ent: string; defV: string = "") : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: bool; defV: bool = false) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: float; defV: float = 0f) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: double; defV: double = 0lf) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: int; defV: int = 0) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: uint; defV: uint = 0x0) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: int64; defV: int64 = 0) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: uint64; defV: uint64 = 0x0) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: int8; defV: int8 = int8(0)) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: uint8; defV: uint8 = uint8(0)) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: int16; defV: int16 = int16(0)) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: uint16; defV: uint16 = uint16(0)) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
from_JV(v: JsonValue const?; ent: bitfield; defV: bitfield = bitfield()) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
  • v : JsonValue ?

  • ent : bitfield<>

  • defV : bitfield<>

from_JV(v: JsonValue const?; ent: bitfield8:uint8<>; defV: bitfield8 = bitfield8()) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
  • v : JsonValue ?

  • ent : bitfield : uint8<>

  • defV : bitfield8

from_JV(v: JsonValue const?; ent: bitfield16:uint16<>; defV: bitfield16 = bitfield16()) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
  • v : JsonValue ?

  • ent : bitfield : uint16<>

  • defV : bitfield16

from_JV(v: JsonValue const?; ent: bitfield64:uint64<>; defV: bitfield64 = bitfield64()) : auto()

Parse a JSON value and return the corresponding native value.

Arguments
  • v : JsonValue ?

  • ent : bitfield : uint64<>

  • defV : bitfield64

JV(v: auto(VecT)) : auto()

Creates JsonValue out of value.

Arguments
  • v : auto(VecT)

from_JV(v: JsonValue const?; ent: auto(VecT); defV: VecT = VecT()) : auto()

Parse a JSON value and return the corresponding vector value.

Arguments
  • v : JsonValue ?

  • ent : auto(VecT)

  • defV : VecT

from_JV(v: JsonValue const?; anything: table<auto(KT), auto(VT)>) : auto()

Parse a JSON value and return the corresponding table value.

Arguments
  • v : JsonValue ?

  • anything : table<auto(KT);auto(VT)>

from_JV(v: JsonValue const?; anything: auto(TT)) : auto()

Parse a JSON value and return the corresponding value of any type. This is the main dispatch function that handles various types.

Arguments
JV(value: auto(TT)) : JsonValue?()

Creates JsonValue out of value. This is the main dispatch function that handles various types.

Arguments
  • value : auto(TT)

JV(val1: auto; val2: auto) : JsonValue?()

Creates array of two JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

JV(val1: auto; val2: auto; val3: auto) : JsonValue?()

Creates array of three JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto) : JsonValue?()

Creates array of four JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto) : JsonValue?()

Creates array of five JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto; val6: auto) : JsonValue?()

Creates array of six JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

  • val6 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto; val6: auto; val7: auto) : JsonValue?()

Creates array of seven JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

  • val6 : auto

  • val7 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto; val6: auto; val7: auto; val8: auto) : JsonValue?()

Creates array of eight JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

  • val6 : auto

  • val7 : auto

  • val8 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto; val6: auto; val7: auto; val8: auto; val9: auto) : JsonValue?()

Creates array of nine JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

  • val6 : auto

  • val7 : auto

  • val8 : auto

  • val9 : auto

JV(val1: auto; val2: auto; val3: auto; val4: auto; val5: auto; val6: auto; val7: auto; val8: auto; val9: auto; val10: auto) : JsonValue?()

Creates array of ten JsonValues.

Arguments
  • val1 : auto

  • val2 : auto

  • val3 : auto

  • val4 : auto

  • val5 : auto

  • val6 : auto

  • val7 : auto

  • val8 : auto

  • val9 : auto

  • val10 : auto

21.5. Uncategorized

JsonValue const? ==const?[](a: JsonValue const? ==const; key: string) : JsonValue?()

Returns the value of the key in the JSON object, if it exists.

Arguments
JsonValue? ==const?[](a: JsonValue? ==const; key: string) : JsonValue?()

Returns the value of the key in the JSON object, if it exists.

Arguments
JsonValue const? ==const?.(a: JsonValue const? ==const; key: string) : JsonValue?()

Returns the value of the key in the JSON object, if it exists.

Arguments
JsonValue? ==const?.(a: JsonValue? ==const; key: string) : JsonValue?()

Returns the value of the key in the JSON object, if it exists.

Arguments
JsonValue const? ==const?[](a: JsonValue const? ==const; idx: int) : JsonValue?()

Returns the value of the index in the JSON array, if it exists.

Arguments
JsonValue? ==const?[](a: JsonValue? ==const; idx: int) : JsonValue?()

Returns the value of the index in the JSON array, if it exists.

Arguments
JsonValue const???(a: JsonValue const?; val: double) : double()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: float) : float()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: int8) : int8()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: int16) : int16()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: int) : int()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: int64) : int64()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: uint8) : uint8()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: uint16) : uint16()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: uint) : uint()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: uint64) : uint64()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: bool) : bool()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const???(a: JsonValue const?; val: string) : string()

Returns the value of the JSON object, if it exists, otherwise returns the default value.

Arguments
JsonValue const? ==const?.`value(a: JsonValue const? ==const) : variant<_object:table<string;JsonValue?>;_array:array<JsonValue?>;_string:string;_number:double;_longint:int64;_bool:bool;_null:void?> const?()

Returns the value of the JSON object, if it exists.

Arguments
JsonValue? ==const?.`value(a: JsonValue? ==const) : variant<_object:table<string;JsonValue?>;_array:array<JsonValue?>;_string:string;_number:double;_longint:int64;_bool:bool;_null:void?>?()

Returns the value of the JSON object, if it exists.

Arguments
parse_json_annotation(name: string; annotation: array<tuple<name:string;data:variant<tBool:bool;tInt:int;tUInt:uint;tInt64:int64;tUInt64:uint64;tFloat:float;tDouble:double;tString:string;nothing:any>>>) : JsonFieldState()

Parse JSON field annotations and return the corresponding JsonFieldState.

Arguments
  • name : string

  • annotation : array<tuple<name:string;data: RttiValue >>