object functionsObject functions available through the builtin object 'object'.
object.defaultobject.evalobject.eval_templateobject.formatobject.has_keyobject.has_valueobject.keysobject.sizeobject.typeofobject.kindobject.valuesobject.from_jsonobject.to_jsonobject.defaultobject.default <value> <default>
The default value is returned if the input value is null or an empty string "". A string containing whitespace characters will not resolve to the default value.
value: The input value to check if it is null or an empty string.default: The default value to return if the input value is null or an empty string.The default value is returned if the input value is null or an empty string "", otherwise it returns value
input Try out
{{ undefined_var | object.default "Yo" }}
output
Yo
object.evalobject.eval <value>
The evaluates a string as a scriban expression or evaluate the passed function or return the passed value.
value: The input value, either a scriban template in a string, or an alias function or directly a value.The evaluation of the input value.
input Try out
{{ "1 + 2" | object.eval }}
output
3
object.eval_templateobject.eval_template <value>
The evaluates a string as a scriban template or evaluate the passed function or return the passed value.
value: The input value, either a scriban template in a string, or an alias function or directly a value.The evaluation of the input value.
input Try out
{{ "This is a template text {{ 1 + 2 }}" | object.eval_template }}
output
This is a template text 3
object.formatobject.format <value> <format> <culture>?
Formats an object using specified format.
value: The input valueformat: The format string.culture: The culture as a string (e.g en-US). By default the culture from is usedinput Try out
{{ 255 | object.format "X4" }}
{{ 1523 | object.format "N2" "en-US" }}
output
00FF
1,523.00
object.has_keyobject.has_key <value> <key>
Checks if the specified object as the member key
value: The input object.key: The member name to check its existence.true if the input object contains the member key; otherwise false
input Try out
{{ product | object.has_key "title" }}
output
true
object.has_valueobject.has_value <value> <key>
Checks if the specified object as a value for the member key
value: The input object.key: The member name to check the existence of its value.true if the input object contains the member key and has a value; otherwise false
input Try out
{{ product | object.has_value "title" }}
output
true
object.keysobject.keys <value>
Gets the members/keys of the specified value object.
value: The input object.A list with the member names/key of the input object
input Try out
{{ product | object.keys | array.sort }}
output
["title", "type"]
object.sizeobject.size <value>
Returns the size of the input object.
value: The input object.The size of the input object.
input Try out
{{ [1, 2, 3] | object.size }}
output
3
object.typeofobject.typeof <value>
Returns string representing the type of the input object. The type can be string, boolean, number, array, iterator and object
value: The input object.input Try out
{{ null | object.typeof }}
{{ true | object.typeof }}
{{ 1 | object.typeof }}
{{ 1.0 | object.typeof }}
{{ "text" | object.typeof }}
{{ 1..5 | object.typeof }}
{{ [1,2,3,4,5] | object.typeof }}
{{ {} | object.typeof }}
{{ object | object.typeof }}
output
boolean
number
number
string
iterator
array
object
object
object.kindobject.kind <value>
Returns string representing the type of the input object. The type can be string, bool, byte, sbyte, ushort, short, uint, int,
ulong, long, float, double, decimal, bigint, enum, range, array, function and object
value: The input object.This function is newer than object.typeof and returns more detailed results about the types (e.g instead of number, returns int or double)
input Try out
{{ null | object.kind }}
{{ true | object.kind }}
{{ 1 | object.kind }}
{{ 1.0 | object.kind }}
{{ "text" | object.kind }}
{{ 1..5 | object.kind }}
{{ [1,2,3,4,5] | object.kind }}
{{ {} | object.kind }}
{{ object | object.kind }}
output
bool
int
double
string
range
array
object
object
object.valuesobject.values <value>
Gets the member's values of the specified value object.
value: The input object.A list with the member values of the input object
input Try out
{{ product | object.values | array.sort }}
output
["fruit", "Orange"]
object.from_jsonobject.from_json <json>
Converts the json to a scriban value. Object, Array, string, etc. Only available in net7.0+
json: The json to deserialize.Returns the scriban value
input Try out
{{
obj = `{ "foo": 123 }` | object.from_json
obj.foo
}}
output
123
object.to_jsonobject.to_json <value>
Converts the scriban value to JSON. Only available in net7.0+
value: The input object.A JSON representation of the value
input Try out
{{ { foo: "bar", baz: [1, 2, 3] } | object.to_json }}
{{ true | object.to_json }}
{{ null | object.to_json }}
output
{"foo":"bar","baz":[1,2,3]}
true
null
Note: This document was automatically generated from the source code using
Scriban.DocGen.