# -*- coding: utf-8 -*-
import json
from pprint import pprint
drink_list = [23,601,633,673,607,662,6622,6014,6104,615,038,606,607,627,6094]
filename = (r'C:\Users\desktop\pizza\123template.json')
with open(filename, 'r') as f:
data = f.read()
try:
template = json.loads(data)
except Exception:
# this file can also be here
print('json exception')
raise
for output in drink_list:
print(output)
temp = template.copy()
temp["meta"]["sodanumber"] = output
with open(r'C:\Users\desktop\pizza\123\{}.json'.format(output, indent=40), 'w', encoding='cp1252') as f:
data = json.dumps(temp)
f.write(data)
# pprint.pprint(temp, width=60)
IndentationError: unindent does not match any outer indentation level.
But I think it's more than a simple indention. I can get my console to change formatting, but need the formatting to be changed in the actual output file. But where would I add my additional formatting to my "with open" line?
Have been reading material for 4 hours on this, and simple examples, but does the pprint do most of the work?
Current output is tons of work-wrapped text. Output needs to look like below. How can I get it to look like this?:
{
"meta": {
"drinkNumber": 662,
"effectiveDate": "2016-10-12 16:00:31",
"documentType": "checkout-device"
},
"documents": [
{
"code": "Checkout2",
"name": "Printer 2",
"port": "COM2",
"type": "LABEL",
Current Output:
{ "meta": { "drinkNumber": 662, "effectiveDate": "2016-10-12 16:00:31", "documentType": "checkout-device" },"documents": [{
"code": "Checkout2","name": "Printer 2","port": "COM2","type": "LABEL",