-
Notifications
You must be signed in to change notification settings - Fork 0
JsonKit.Stringify
JsonKit.Stringify
Ƭ StringifyOptions: Object
Type for the options
parameter of stringify.
Name | Type | Description |
---|---|---|
compress? |
boolean | { enable : boolean } |
Determines if the output string will be compressed with lz4js.compress() . Default Value false
|
extended? |
boolean | { enable : boolean ; relaxed? : boolean } |
Determines if the output string is in JSON or EJSON format, additional options to be passed into bson.EJSON.stringify() can be supplied with the long form (only effective if enable is true . Default Value false
|
minify? |
boolean | { enable : boolean ; keyMap? : Record <string , string > } |
Determines if the output string will have some of the keys replaced with a shorter identifier, a custom key map (original:shortened) can be supplied with the long form (only effective if enable is true . Default Value false
|
Ƭ StringifyReplacerArray: (string
| number
)[]
Array
type for the replacer
parameter of stringify.
Refer to the MDN documentation for more details.
Ƭ StringifyReplacerFunction: (this
: any
, key
: string
, value
: any
) => any
▸ (this
, key
, value
): any
Function
type for the replacer
parameter of stringify.
Refer to the MDN documentation for more details.
Name | Type |
---|---|
this |
any |
key |
string |
value |
any |
any
▸ compressString(str
): string
Compresses a string with lz4js.compress()
.
Name | Type | Description |
---|---|---|
str |
string |
The input string |
string
str - The compressed string
▸ stringify(obj
, replacer?
, space?
, options?
): string
Turns the input object into a string.
Remarks
With the custom options, the output string can be either
- a JSON string (identical to
JSON.stringify()
) - an EJSON string (identical to
bson.EJSON.stringify()
) - a minified version of either of the above, where some or specified keys will be replaced with a shorter identifier
- a compressed version (by
lz4js.compress()
) of either of the above
Example
stringify(
{ long_key: "A Large Object" },
(key, val) => {
if (key === "long_key") {
return "A Modified Large Object"
}
return val
},
2,
{
extended: false,
minify: { enable: true, keyMap: { long_key: "lk" } },
compress: false
}
)
Name | Type | Description |
---|---|---|
obj |
any |
The input object |
replacer? |
null | StringifyReplacerArray | StringifyReplacerFunction
|
The replacer parameter of JSON.stringify()
|
space? |
null | string | number
|
The space parameter of JSON.stringify()
|
options? |
null | StringifyOptions
|
The custom options, refer to StringifyOptions for details |
string
The output string
▸ stringify(obj
, options?
): string
Turns the input object into a string.
Remarks
With the custom options, the output string can be either
- a JSON string (identical to
JSON.stringify()
) - an EJSON string (identical to
bson.EJSON.stringify()
) - a minified version of either of the above, where some or specified keys will be replaced with a shorter identifier
- a compressed version (by
lz4js.compress()
) of either of the above
Example
stringify(
{ long_key: "A Large Object" },
{
extended: false,
minify: { enable: true, keyMap: { long_key: "lk" } },
compress: false
}
)
Name | Type | Description |
---|---|---|
obj |
any |
The input object |
options? |
null | StringifyOptions
|
The custom options, refer to StringifyOptions for details |
string
The output string