Ask Your Question
0

Serialise data to JSON in HOT

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

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
0

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

zaneb gravatar image

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

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.:

list_join:
  - ''
  - - 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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

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

Seen: 254 times

Last updated: Oct 25 '18