packageDocumentation module public export namespace JsonUtils { param json param defaultVal returns export function asBool ( json , defaultVal = false ) { return isNullOrUndefined ( json ) ? defaultVal : ! ! json ; } param json param defaultVal returns export function asInt ( json , defaultVal = 0 ) { return ( typeof json === "number" ) ? Math . trunc ( json ) : defaultVal ; } param json param defaultVal returns export function asDouble ( json , defaultVal = 0 ) { return ( typeof json === "number" ) ? json : defaultVal ; } param json param defaultVal returns export function asString ( json , defaultVal = "" ) { return isNullOrUndefined ( json ) ? defaultVal : json . toString ( ) ; } param json returns export function asArray ( json ) { return Array . isArray ( json ) ? json : undefined ; } param json returns export function asObject ( json ) { return "object" === typeof json ? json : undefined ; } param json param key param val param defaultVal export function setOrRemoveNumber ( json , key , val , defaultVal ) { if ( val === defaultVal ) delete json [ key ] ; else json [ key ] = val ; } param json param key param val param defaultVal export function setOrRemoveBoolean ( json , key , val , defaultVal ) { if ( val === defaultVal ) delete json [ key ] ; else json [ key ] = val ; } param json returns export function isEmptyObject ( json ) { return "object" === typeof json && 0 === Object . keys ( json ) . length ; } param json returns export function isEmptyObjectOrUndefined ( json ) { return undefined === json || isEmptyObject ( json ) ; } function isNullOrUndefined ( json ) { return null === json || undefined === json ; } param value returns export function isNonEmptyObject ( value ) { return ! isEmptyObjectOrUndefined ( value ) ; } /**
     * Convert the input object into a "pure" JavaScript object, with only instances of "object" or primitives in the returned value.
     * Works recursively for object members, and over arrays entries. Calls "toJSON" on any members that implement it.
     */ export function toObject ( val ) { if ( typeof val === "boolean" || typeof val === "number" || typeof val === "string" ) return val ; if ( typeof val !== "object" ) return undefined ; if ( typeof val . toJSON !== "undefined" ) return toObject ( val . toJSON ( ) ) ; if ( Array . isArray ( val ) ) { const arr = new Array ( val . length ) ; val . forEach ( ( el , i ) => { arr [ i ] = toObject ( el ) ; } ) ; return arr ; } const out = { } ; Object . getOwnPropertyNames ( val ) . forEach ( ( prop ) => { const transformVal = toObject ( val [ prop ] ) ; if ( transformVal !== undefined ) out [ prop ] = transformVal ; } ) ; return out ; } }