diff --git a/mistral/utils/expression_utils.py b/mistral/utils/expression_utils.py index a0dd5ca18..e5aefd573 100644 --- a/mistral/utils/expression_utils.py +++ b/mistral/utils/expression_utils.py @@ -17,6 +17,7 @@ from functools import partial from oslo_serialization import jsonutils from stevedore import extension +import yaml import yaql from mistral.db.v2 import api as db_api @@ -271,3 +272,11 @@ def global_(context, var_name): wf_ex = db_api.get_workflow_execution(context['__execution']['id']) return wf_ex.context.get(var_name) + + +def json_parse_(context, data): + return jsonutils.loads(data) + + +def yaml_parse_(context, data): + return yaml.safe_load(data) diff --git a/releasenotes/notes/yaml-json-parse-53217627a647dc1d.yaml b/releasenotes/notes/yaml-json-parse-53217627a647dc1d.yaml new file mode 100644 index 000000000..05db48cfc --- /dev/null +++ b/releasenotes/notes/yaml-json-parse-53217627a647dc1d.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add yaml_parse and json_parse expression functions. Each accepts a string + and will parse as either json or yaml, and return an object. diff --git a/setup.cfg b/setup.cfg index 6615b5da2..fff40150c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -83,6 +83,8 @@ mistral.expression.functions = execution = mistral.utils.expression_utils:execution_ env = mistral.utils.expression_utils:env_ uuid = mistral.utils.expression_utils:uuid_ + json_parse = mistral.utils.expression_utils:json_parse_ + yaml_parse = mistral.utils.expression_utils:yaml_parse_ mistral.expression.evaluators = yaql = mistral.expressions.yaql_expression:InlineYAQLEvaluator