replaceVariables

Search variables #{variable_name} and replace them with the values from json

string
replaceVariables
(
const string data
,
const Json variables
,
const string prefix = ""
)

Examples

replace variables

Json data = Json.emptyObject;
data["one"] = "1";
data["second"] = Json.emptyObject;
data["second"]["value"] = "2";

"#{one}-#{second.value}".replaceVariables(data).should.startWith("1-");
"#{one}-#{second.value}".replaceVariables(data).should.endWith("-2");

should not replace variables on undefined data

Json data;

"#{one}-#{second.value}".replaceVariables(data).should.startWith("#{one}-");
"#{one}-#{second.value}".replaceVariables(data).should.endWith("-#{second.value}");

Meta