Last active
March 14, 2019 08:39
-
-
Save luckylittle/b4d08b508982c9996a0cd326a598f904 to your computer and use it in GitHub Desktop.
Closing the JSON properly in Ansible (replace last comma with curly braces)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sometimes there are moments, when you construct JSON in a really dirty way by just appending key/value pairs and adding comma at the end. | |
# You will end up with something like this: | |
# { | |
# "big_key": { | |
# "small_key1": "small_value1", | |
# "small_key2": "small_value2", | |
# "small_key3": "small_value3", | |
# And then to make this valid JSON, you need to replace the last comma with curly braces. | |
# This is an example how to do it in Ansible using regex in the replace module: | |
- name: Fix the broken JSON | |
replace: | |
path: "unfinished.json" | |
regexp: ',.*$\n\Z' | |
replace: '\n } \n}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment