Conversion Functions#
bool
- Convert to Boolean#
Convert element to boolean.
import ison
dicData = {
"bool(true)": "$bool{true}",
"bool(1)": "$bool{$int{1}}",
"bool(2.34)": "$bool{$float{2.34}}",
"bool(0)": "$bool{$int{0}}"
}
dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
"bool(true)": true,
"bool(1)": true,
"bool(2.34)": true,
"bool(0)": false
}
float
- Convert to Float#
Convert element to floating point number.
import ison
dicData = {
"result": "$float{3.1415}"
}
dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
"result": 3.1415
}
int
- Convert to Integer#
Convert element to integer.
import ison
dicData = {
"result": "$int{42}"
}
dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
"result": 42
}
json
- Convert to JSON#
Convert object to JSON string.
import ison
dicData = {
"__locals__": {
"dicA": { "a": 1 }
},
"result": "$json{$dicA}"
}
dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
"result": "{\n \"a\": 1\n}"
}
to-ref-path
- Convert to Reference Path#
Convert a path string as in a/b/c
to an ISON reference string a:b:c
.
import ison
dicData = {
"__locals__": {
"dicA": {
"a": {
"b": {
"c": 1
}
}
},
"sPath": "a/b/c"
},
"result": "${$dicA:$to-ref-path{$sPath}}"
}
dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
"result": 1
}