Skip to content

Access with default value: value

Overview

In many situations such as configuration files, missing values are not exceptional, but may be treated as if a default value was present.

Example

Consider the following JSON value:

{
    "logOutput": "result.log",
    "append": true
}

Assume the value is parsed to a json variable j.

expression value
j {"logOutput": "result.log", "append": true}
j.value("logOutput", "logfile.log") "result.log"
j.value("append", true) true
j.value("append", false) true
j.value("logLevel", "verbose") "verbose"

Note

Exceptions