0

I have defined an object with a few attributes in my values.yaml file:

serverOptions:
    defaultUrl:
        p1: abc
        p2: def
    cpu_request:
        p1: abc
        p2: def
    mem_request:
        p1: abc
        p2: def

I am saving these data to a server_options json file in configmap.yaml using this code:

data:
    server_options.json: |
        {{ toJson .Values.serverOptions }}

It works but the initial "list" of attributes gets alphabetically ordered. This is the file's content

{"cpu_request":{"p1":"abc","p2":"def"},"defaultUrl":{"p1":"abc","p2":"def"},"mem_request":{"p1":"abc","p2":"def"}}

Is there a way to keep the original ordering?

Naigel
  • 9,086
  • 16
  • 65
  • 106

1 Answers1

1

Json dictionaries aren't ordered, so no that's not possible. They may be alphabetically ordered when printed but that's only for readability.

Alassane Ndiaye
  • 4,427
  • 1
  • 10
  • 19
  • Theoretically, one should not count on ordering when working with Json dictionaries, but I was curious about this specific implementation. I guess the ordering here is not for readability purposes but for other technical reasons. – Naigel Sep 18 '19 at 13:10