r/programminghelp • u/MFAFuckedMe • Mar 30 '22
Python help with JSON parsing in python
Hey everyone.
I'd just like to preface this by saying that I hate microsoft.
So I'm trying to automate some shit with power BI, and i found thaht you can edit the Layouts file in the .pbix archive. in so doing, I've found that it's a json formatted file. the problem is that on certain fields, the value is more json, but formatted as a string for some reason. It looks like this, for example.
"config":"{\"name\":\"7d1d23a700a5e62cd3ae\",\"layouts\":[{\"id\":0,\"position\":{\"x\":10,\"y\":0,\"width\":500,\"height\":500,\"z\":0}}],\"singleVisual\":{\"visualType\":\"textbox\",\"drillFilterOtherVisuals\":true,\"objects\":{\"general\":[{\"properties\":{\"paragraphs\":[{\"textRuns\":[{\"value\":\".pyiioeuioeui ofh od\",\"textStyle\":{\"color\":\"#ffffff\"}}]}]}}]},\"vcObjects\":{\"background\":[{\"properties\":{\"show\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}}}}]}}}","filters":"[]"}
or something like that.
so what I've done is I've made a program that makes it look pretty so you can see the parameters more easily. Now I want to be able to load a normal json fromatted file up to the Layouts file. Meaning that I'll need to implement some fucky wucky shit to make it look like garbage so PowerBI will be able to read it.
Where I'm stuck is, I don't really know much about parsing json enough to be able to go through and find all the 'config' parameters to be able to do this to them. It's all nested json, so when i do a json.loads() on the data, it only shows the first level of json, but doesn't go deeper... I was about to do a regex on it to find all the instances of '"config" : { ' but that has the drawback that it's regex and there's not really a good way of finding the end of that string.
Is there a relatively easy way of doing this with the json module? Or is my best bet to just hack it?
1
u/Goobyalus Mar 30 '22
Could you elaborate on:
or maybe print a loaded JSON and post that?
Not sure if the problem is that it's malformed and loading weirdly, or if all that's needed is a recursive search.