You can use the following re.sub to do the replacements (demo).
Edit for OP's comments:
Given that the file is fairly small, I'd iterate through it while reading, applying the substitution as I go, and then dump all the subbed lines into the same location.
import re
file_path = "/tmp/74987707.txt" # substitute your own
output_lines = []
with open(file_path, mode="rt") as f:
for line in f:
subbed_line = re.sub(
r'("position": \[\d+(?:\.?\d*), \d+(?:\.?\d*))(])',
r'\1, 0\2',
line
)
output_lines.append(subbed_line)
with open(file_path, mode="wt") as f:
f.writelines(output_lines)
Regex explanation:
- group 1
("position": \[\d+(?:\.?\d*), \d+(?:\.?\d*))
( start
"position": \[ match exactly (escaping [)
\d+ match one or more digit
(?:\.?\d*) non capturing group, match a possible literal dot . and one or more digits
, match exactly
\d+(?:\.?\d*) see above
) end
- group 2
(\])
( start
\] match exactly (escaping ])
) end