Skip to content

Instantly share code, notes, and snippets.

@yuvipanda
Created May 15, 2020
Embed
What would you like to do?
{'frontends': {'frontend__2F': {'backend': 'backend__2F', 'passHostHeader': True, 'routes': {'test': {'rule': 'PathPrefix:/', 'data': '{"hub": true}'}}}, 'frontend__2Fuser_2Fyuvipanda': {'backend': 'backend__2Fuser_2Fyuvipanda', 'passHostHeader': True, 'routes': {'test': {'rule': 'PathPrefix:/user/yuvipanda', 'data': '{"user": "yuvipanda", "server_name": ""}'}}}, 'frontend__2Fuser_2Fusername': {'backend': 'backend__2Fuser_2Fusername', 'passHostHeader': True, 'routes': {'test': {'rule': 'PathPrefix:/user/username', 'data': '{"user": "username", "server_name": ""}'}}}}, 'backends': {'backend__2F': {'servers': {'server1': {'url': 'http://127.0.0.1:8081', 'weight': 1}}}, 'backend__2Fuser_2Fyuvipanda': {'servers': {'server1': {'url': 'http://127.0.0.1:41224', 'weight': 1}}}, 'backend__2Fuser_2Fusername': {'servers': {'server1': {'url': 'http://127.0.0.1:38844', 'weight': 1}}}}}
Traceback (most recent call last):
File "tbjh/test.py", line 9, in <module>
toml.dumps(d)
File "/Users/yuvipanda/code/the-batchiest-jupyterhub/conda/lib/python3.7/site-packages/toml/encoder.py", line 67, in dumps
raise ValueError("Circular reference detected")
ValueError: Circular reference detected
{
"frontends": {
"frontend__2F": {
"backend": "backend__2F",
"passHostHeader": true,
"routes": {
"test": {
"rule": "PathPrefix:/",
"data": "{\"hub\": true}"
}
}
},
"frontend__2Fuser_2Fyuvipanda": {
"backend": "backend__2Fuser_2Fyuvipanda",
"passHostHeader": true,
"routes": {
"test": {
"rule": "PathPrefix:/user/yuvipanda",
"data": "{\"user\": \"yuvipanda\", \"server_name\": \"\"}"
}
}
},
"frontend__2Fuser_2Fusername": {
"backend": "backend__2Fuser_2Fusername",
"passHostHeader": true,
"routes": {
"test": {
"rule": "PathPrefix:/user/username",
"data": "{\"user\": \"username\", \"server_name\": \"\"}"
}
}
}
},
"backends": {
"backend__2F": {
"servers": {
"server1": {
"url": "http://127.0.0.1:8081",
"weight": 1
}
}
},
"backend__2Fuser_2Fyuvipanda": {
"servers": {
"server1": {
"url": "http://127.0.0.1:41224",
"weight": 1
}
}
},
"backend__2Fuser_2Fusername": {
"servers": {
"server1": {
"url": "http://127.0.0.1:38844",
"weight": 1
}
}
}
}
}
import toml
import json
with open('problematic.json') as f:
d = json.load(f)
print(d)
toml.dumps(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment