This is an attempt to provide support for arrays when expanding keys for JSON and Yaml.
It was motivated by using Consul for Spring Boot services, which allows for array configuration data with either comma-separated lists or property names ending with indexes in [] -- e.g. my/array/key[0]. While the existing loader provided fine support for loading Yaml files un-expanded, we wanted to expand keys in order to observe changes on a per-key level directly from Consul.
I believe that would address the now-closed #71 issue. It builds on the work done by @kapekost for better Yaml support, but adds two new properties to control how arrays are formatted.
array_format: Controls how primitive arrays are formatted. Options:
'none': Ignore them (default and current behavior)
'json': Output JSON-formatted value (the strategy employed in the work by @kapekost)
separator: Use the provided separator when joining the arrays to support things such as comma-separated lists.
array_key_format: Controls how arrays can be formatted as individual keys. Instead of picking a single format, this expects a format string using _ as a reserved-value for the array name and # as a reserved value for array "index". This allows arbitrary arrays to be formatted -- e.g. the JSON string {"my":{"array":{"key":[{"with_sub_obj":{"foo":"bar"}}]}}} becomes my/array/key/0/with_sub_obj/foo. The default behavior is to not output any keys, so the existing behavior is unchanged without additional configuration.
These values are described in the readme, and the code is isolated so it could easily be re-used in the discussed refactoring to allow for non-git configuration sources.
This is an attempt to provide support for arrays when expanding keys for JSON and Yaml.
It was motivated by using Consul for Spring Boot services, which allows for array configuration data with either comma-separated lists or property names ending with indexes in
[]
-- e.g.my/array/key[0]
. While the existing loader provided fine support for loading Yaml files un-expanded, we wanted to expand keys in order to observe changes on a per-key level directly from Consul.I believe that would address the now-closed #71 issue. It builds on the work done by @kapekost for better Yaml support, but adds two new properties to control how arrays are formatted.
array_format
: Controls how primitive arrays are formatted. Options:array_key_format
: Controls how arrays can be formatted as individual keys. Instead of picking a single format, this expects a format string using_
as a reserved-value for the array name and#
as a reserved value for array "index". This allows arbitrary arrays to be formatted -- e.g. the JSON string{"my":{"array":{"key":[{"with_sub_obj":{"foo":"bar"}}]}}}
becomesmy/array/key/0/with_sub_obj/foo
. The default behavior is to not output any keys, so the existing behavior is unchanged without additional configuration.These values are described in the readme, and the code is isolated so it could easily be re-used in the discussed refactoring to allow for non-git configuration sources.