Special Functions#

* - Create Structure from String#

Convert the string argument to an object. Expects the string to be JSON parsable.

import ison

dicData = {
    "__locals__": {
        "sA": "{ \"a\": 1, \"b\": 2 }"
    },

    "result": "$*{$sA}",
}

dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
    "result": {
        "a": 1,
        "b": 2
    }
}

Instead of using the escaped quotes in the definition of sA, you can also use the backward quote (`) as in this example:

import ison

dicData = {
    "__locals__": {
        "sA": "{ `a`: 1, `b`: 2 }"
    },

    "result": "$*{$sA}",
}

dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
    "result": {
        "a": 1,
        "b": 2
    }
}

If you need to nest stings within string, you can use the function $S{}, which allows arbitrary deep nesting.

import ison

dicData = {
    "__locals__": {
        "sA": "{ $S{a}: 1, $S{b}: $S{{$S{c}: 1}} }"
    },

    "result": "$*{$sA}",
}

dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
    "result": {
        "a": 1,
        "b": "{\"c\": 1}"
    }
}

set-log-path - Set Logging Path#

You can set a logging path in three ways with $set-log-path{}:

  1. Without arguments the current working directory is used a logging path and a filename is automatically generated.

  2. Give a path without filename. In this case, a filename is automatically generated and the path is created.

  3. Give a full filepath. If the path does not exist, it is created.

import ison

dicData = {
    "__locals__": {
        "sLogPath": "$set-log-path{}",
        "dicA": { "Hello": "World" },
        "sLog": "$print{Variable 'dicA':, $json{$dicA}, }"
    },
    # Uncomment the following line to see the path of the log file
    # in the printed output.
    # "log-path": "${sLogPath}",
    "result": "$dicA"
}

try:
    dicResult = ison.run.Run(xData=dicData, bPrintWarnings=True)
    print(ison.run.ToString(dicResult))

except Exception as xEx:
    print(str(xEx))
# endtry
{
    "result": {
        "Hello": "World"
    }
}

S - String#

This function is mainly used internally when converting structures to lambda functions. Internally lambda functions are strings. To support arbitrarily nested string expressions the structure $S{} is used instead of double quotes.

import ison

dicData = {
    "result": "$S{Hello $S{Christian}}",
}

dicResult = ison.run.Run(xData=dicData)
print(ison.run.ToString(dicResult))
{
    "result": "\"Hello \\\"Christian\\\"\""
}