particledecay / ansible-jsonpatch

An Ansible module for patching JSON files
MIT License
118 stars 27 forks source link

write pretty formatted json file #10

Closed JOJ0 closed 4 years ago

JOJ0 commented 4 years ago

Hi, I dont' know if this is an issue with the module or generally with my bad Ansible knowledge:

The manipulated json file is being removed all (human readable) formatting (\n etc).

 - name: "edit config.json"
    json_patch:
      src: "{{riot_path}}/config.sample.json"
      dest: "{{riot_path}}/config.json"
      backup: yes
      operations:
        - op: replace
          path: "/default_server_config/m.homeserver/server_name"
          value: "my.server.com"

I also tried with first copying config.sample.json to config.json and then just using src: with json_patch so it overwrites the original filename - it's the same - all formatting gets lost and config.json is a proper json but in an unpretty "oneline format".

Is this me using it wrong or is it supposed to be like that?

Thanks in advance Jojo

particledecay commented 4 years ago

@JOJ0 sorry it took so long to respond (GitHub's notifications are hot garbage).

There is actually a pretty print option if you care about writing the JSON back in a human-readable format, just use pretty: yes.

I realize this isn't in the README. I'll create an issue to add that.