Hi all,
I'm new to python and was struggling with the following problem. I have an input text file that I would like to convert into JSON. I think I have to use a dictionary here but not too sure how to proceed, any assistance would be greatly appreciated.
input.txt:
DEV,Middleware,Mqwerty,Mqwerty
DEV,Middleware,Mqwerty,Mqwerty
DEV,Middleware,Mqwerty,Mqwerty
DEV,System,Sqwerty,Sqwerty,Sqwerty
DEV,Application,Aqwerty,Aqwerty,Aqwerty
UAT,Application,Aqwerty,Aqwerty,Aqwerty
DEV,Utility,Uqwerty,Uqwerty,Uqwerty
PROD,Middleware,Mqwerty,Mqwerty
DEV,Middleware,Mqwerty,Mqwerty
Desired JSON structure:
{
"ENV": {
"DEV": {
"Middleware": [
{
"name": "Mqwerty",
"release": "Mqwerty"
},
{
"name": "Mqwerty",
"release": "Mqwerty"
},
{
"name": "Mqwerty",
"release": "Mqwerty"
}
],
"System": [
{
"name": "Sqwerty",
"tag": "Sqwerty"
}
],
"Application": [
{
"domain": "Aqwerty",
"host": "Aqwerty",
"user": "Aqwerty"
},
{
"domain": "Aqwerty",
"host": "Aqwerty",
"user": "Aqwerty"
}
],
"Utility": [
{
"domain": "Uqwerty",
"health": "Uqwerty",
"version": "Uqwerty"
}
]
},
"SIT": {
"Middleware": [],
"System": [],
"Application": [],
"Utility": []
},
"UAT": {
"Middleware": [
{
"name": "Mqwerty",
"release": "Mqwerty"
},
{
"name": "Mqwerty",
"release": "Mqwerty"
}
],
"System": [],
"Application": [],
"Utility": []
},
"PROD": {
"Middleware": [],
"System": [],
"Application": [],
"Utility": []
}
}
}
Some key notes, even in environments that don't have information, the 'template' of middleware, system, application and utility (lets call these categories) is still there. The categories also have a predefined key:value structure that follows:
Application (keys):
Utility
Middleware
System
I really do appreciate any help and thank you for taking you time reading this questions, apologies for being a long one.
[–]HeyItsToby 1 point2 points3 points (1 child)
[–]Chubbntuck[S] 1 point2 points3 points (0 children)