Closed lakshmi-kannan closed 4 years ago
+1
May I urge you to implement from_json_string and from_yaml_string. After discussion in slack with @lakshmi-kannan it was explained that from_json_string
shouldn't be necessary because stackstorm automatically detects json formatted results.
Despite the detection feature, the use case I'm confronted with is the following:
When fetching a key using the consul pack, the response is a JSON object in the following form:
{
"LockIndex": 0,
"ModifyIndex": 11431146,
"Value": "[u'pkg-01.example.com', u'pkg-02.example.com', u'pkg-03.example.com', u'pkg-04.example.com']",
"Flags": 0,
"Key": "automation/pkg/hosts",
"CreateIndex": 11430978
}
Consul's Value
can only be a string data type. The above example was created using the following mistral+YAQL action:
record_hosts:
action: consul.put
input:
key: "automation/<% $.role %>/hosts"
value: <% str($.hosts) %>
on-success: record_hosts_in_progress
YAQL casts hosts
(type: list) to string so the result conforms with consul.put
's value
parameter which expects a string data type. Having a to_json_string function would allow YAQL to serialise an object to a string in valid JSON format. Having from_json_string would allow the deserialisation of the same string back into a Python object.
I hope the use case is clear and compelling enough to implement to/from json string functions in YAQL.
We support custom filters in st2 land which works well in action chains. We need to port these filters to mistral https://docs.stackstorm.com/reference/jinja.html#applying-filters-with-jinja.