Module: @tsmx/json-tools

Namespaces

obfuscate
transform

Methods

(static) getDepth(obj, includeArraysopt) → {number}

Retrieves the depth (nesting level) of a JSON object. Root level is considered to be zero.
Parameters:
Name Type Attributes Default Description
obj Object the object to inspect
includeArrays boolean <optional>
true sets if objects in arrays should be considered
Source:
Returns:
the zero-based depth of the JSON
Type
number

(static) isComplex(obj, includeArraysopt) → {boolean}

Checks if a JSON object is complex, meaning it has nested objects (depth > 0).
Parameters:
Name Type Attributes Default Description
obj Object the object to inspect
includeArrays boolean <optional>
true sets if objects in arrays should be considered
Source:
Returns:
true, if the JSON is complex
Type
boolean

(static) isSimple(obj, includeArraysopt) → {boolean}

Checks if a JSON object is simple, meaning it has no nested objects (depth == 0).
Parameters:
Name Type Attributes Default Description
obj Object the object to inspect
includeArrays boolean <optional>
true sets if objects in arrays should be considered
Source:
Returns:
true, if the JSON is simple
Type
boolean

(static) typeStats(obj) → {Map}

Parses all values of an object and returns the number of occurances per type in a Map. Does a deep-parsing including subobjects and array elements.
Parameters:
Name Type Description
obj Object the object to inspect
Source:
Returns:
a Map cotaining the number of occurances for every type, e.g. { 'string' => 3, 'number' => 1 ... }
Type
Map