Convert JSON FILE to XML FILE using POWERSHELL (1 Viewer)

MBMSOFT

Registered User.
Local time
Today, 12:43
Joined
Jan 29, 2010
Messages
90
I need to convert json file from web to xml file and i need very simple way... There are several data I need from json response... There are a lot of around but they are not very clear...
I found some samples like this:
PS c:\0> ConvertTo-Xml -InputObject temp_JSON.json -As String
PS c:\0> ConvertTo-Xml -InputObject temp_JSON.json -As document

but I can't see or find result
Where I'm wrong...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:43
Joined
Oct 29, 2018
Messages
21,358
Hi. According to MS documentation, the CovertTo-XML cmdlet produces an XML structure in memory.
 

MBMSOFT

Registered User.
Local time
Today, 12:43
Joined
Jan 29, 2010
Messages
90
yes but how can I get the xml file after i run script
I run this
PS c:\0> ConvertTo-Xml -InputObject temp_JSON.json -As document
where is the file
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:43
Joined
Oct 29, 2018
Messages
21,358
Hi. I'm no PowerShell user, so I unsuccessfully gave it a try last night and decided to sleep over it. This morning, I gave it another try, and this one worked for me.

I am not saying this is how you would do it, but it might help with what you're trying to do. Good luck!

Code:
new-item test.xml
$data = $(get-content 'json.txt' -raw)
$json = convertfrom-json -inputobject $data
[xml]$xml = convertto-xml -depth 1000 $json -notypeinformation
set-content test.xml $xml.outerxml
[code]
 

Users who are viewing this thread

Top Bottom