Ask Your Question

Serialise data to JSON in HOT

asked 2016-11-12 10:25:17 -0600

zaneb gravatar image

In a Heat template, I need to specify some data as a serialised JSON string, but the data source (e.g. the get_attr function) provides a dict or list. How can I serialise the dict within the template?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-11-12 10:28:28 -0600

zaneb gravatar image

updated 2018-10-25 13:35:21 -0600

The list_join function converts the list members to JSON if they are lists or dicts (though unfortunately not numbers or booleans). So this can be accomplished by doing list_join on a single-member list. e.g.:

  - ''
  - - foo: bar
      blarg: wibble

will resolve to the JSON serialisation:

{"foo": "bar", "blarg": "wibble"}

Note that this requires a heat_template_version of 2015-10-15 or later. Earlier template versions accepted only strings to join.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2016-11-12 10:25:17 -0600

Seen: 312 times

Last updated: Oct 25 '18