Modifying view.json externally with Python


We are trying to make some adjustments to perspective views in bulk, by using python to modify the view.json of each file.

Currently we are doing so by loading them into an object with json.load(), making the modification, and writing them back to a json string with json.dump().

However when we do this the loads method is converting the escaped unicode characters in the script bindings back to strings
"script": "\tprint([\u0027Hello World!\u0027)"
"script": " print('Hello World!')"

Does anyone have any idea how we can do this in a scalable/non-invasive way so that we don’t have to figure out each needed unicode character and then replace them?

I appreciate any help!

Current script (Removing parts not relevant to example):

import json

filePath = "./Example/view.json"
fileName = "view.json"

fr = open(filePath)

# Open json object as python dict
viewDict = json.load(fr)

# Make our change
viewDict['root']['custom']['exampleProperty'] = "Hello world!"

# Convert the object back into a json string
newViewJson = json.dumps(viewDict, sort_keys=True,

# Write json string back to the file
fw = open(filePath, mode='w')

I think it’s anything considered to be unsafe for HTML: