JSON transformation functions
- Source:
Methods
(static) toArray(obj) → {Array}
Converts a JSON object to an Array.
The returned Array will contain a {key, value} object for all root-level object properties.
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object | the object to be converted to a Map |
- Source:
Returns:
an Array containing all of the objects properties
- Type
- Array
(static) toLLM(obj, compactArrays)
Converts a JSON object to a LLM friendly and token-saving notation for further processing in your AIa pplications.
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
* | the object to be converted to the LLM friendly notation |
compactArrays |
* | if set to true, arrays containing only identical objects (same keys and same key order) will be even more compacted in the output, defaults to false if not set |
- Source:
Returns:
a string containing the token-optimized LLM notation of the object
(static) toMap(obj) → {Map}
Converts a JSON object to a Map.
The returned Map will contain all root-level object property values as entries with their property names as the key.
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object | the object to be converted to a Map |
- Source:
Returns:
a Map containing all of the objects properties
- Type
- Map
(static) toProperties(obj, expandArraysopt) → {String}
Converts a JSON object to a properties file string.
Nested subobjects and their values are resolved into own props with full dot-separated path
as key, e.g. country.name=USA country.code=US.
Line endings are '\r\n'.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj |
Object | the object to be converted to a properties string | ||
expandArrays |
boolean |
<optional> |
false | if set to true, creates an own property entry for each array element with a zero-based index, e.g. values.0=7 values.1=13 - if set to false, the complete array is printed as a comma separated string, e.g. values=7,13 |
- Source:
Returns:
a properties file like string
- Type
- String
(static) toPropertiesFlat(obj, expandArraysopt) → {String}
Converts a JSON object to a properties file string.
Only the root level of the object is considered.
Nested subobjects and their values are not resolved further and printed out as stringified JSON, e.g. country={"name":"USA","code":"US"}.
Line endings are '\r\n'.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj |
Object | the object to be converted to a properties string | ||
expandArrays |
boolean |
<optional> |
false | if set to true, creates an own property entry for each array element with a zero-based index, e.g. values.0=7 values.1=13 - if set to false, the complete array is printed as a comma separated string, e.g. values=7,13 |
- Source:
Returns:
a properties file like string
- Type
- String