I am having a problem with splitting this string:
"published": "2018-08-15T08:04:57Z",
I would like to split the 2018-08-15
part from the T08
part. After that the T08...
part needs to be removed. This will be applied to every "published": rule
in the .json file.
I'll have to do this with Python, as I also convert the XML file to JSON.
So in the convert process I would like to remove the T08...
part.
I hope someone can help me and if more clarification is needed, I don't mind giving it :)
Searched the internet, had some look into the .split
, .pop
etc. methods. I am just a rookie at Python still but I want to learn.
Here is my current code:
import xmltodict
import json
#Searching for .xml file to convert
with open ('../../get_url/chocolatey.xml') as fd:
xmlString = fd.read()
#Converting .xml file
print("XML Input (../../get_url/chocolatey.xml):")
print(xmlString)
#Removing certain Characters from strings in file
jsonString = json.dumps(xmltodict.parse(xmlString), indent=4)
jsonString = jsonString.replace("#", "")
jsonString = jsonString.replace("m:", "")
jsonString = jsonString.replace("d:", "")
#jsonString = jsonString.replace('"', '')
#Printing output in Json format
print("\nJson Output (../../get_url/chocolatey.json):")
print(jsonString)
#Applying output to .json file
with open("chocolatey.json", 'w') as fd:
fd.write(jsonString)
Example of the JSON file
},
"published": "2018-08-15T08:04:57Z",
"updated": "2018-08-15T08:04:57Z",
"author": {
"name": "Microsoft"
},