05-15-2015
If you can install
PHP you may try this its easy
PHP Code:
[akshay@localhost JSON2XML]$ cat test.php
<?php
/**
* Convert JSON to XML
* @param string - json
* @return string - XML
*/
function json_to_xml($json)
{
include_once("XML/Serializer.php");
$options = array (
'addDecl' => TRUE,
'encoding' => 'UTF-8',
'indent' => ' ',
'rootName' => 'json',
'mode' => 'simplexml'
);
$serializer = new XML_Serializer($options);
$obj = json_decode($json);
if ($serializer->serialize($obj)) {
return $serializer->getSerializedData();
} else {
return null;
}
}
$sample = <<<EOF
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
EOF;
echo json_to_xml($sample);
?>
PHP Code:
[akshay@localhost JSON2XML]$ php test.php
<?xml version="1.0" encoding="UTF-8"?>
<json>
<menu>
<id>file</id>
<value>File</value>
<popup>
<menuitem>
<value>New</value>
<onclick>CreateNewDoc()</onclick>
</menuitem>
<menuitem>
<value>Open</value>
<onclick>OpenDoc()</onclick>
</menuitem>
<menuitem>
<value>Close</value>
<onclick>CloseDoc()</onclick>
</menuitem>
</popup>
</menu>
</json>
https://drive.google.com/file/d/0B6_...ew?usp=sharing
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Apologies if this has already been covered in this site somewhere, I did try looking but without any success. I am new to the whole XML thing, very late starter, and have a requirement to convert an XML fiule to a CSV fomat. I am crrently working on a Solaris OS. Does anyone have any suggestions,... (2 Replies)
Discussion started by: rossingi_33
2 Replies
2. Shell Programming and Scripting
Hii every one.
I have lots of .html files like:
<html>
<title>
</title>
<head>
</head>
<body>
<ul id="SummaryRatings">4 stars </ul>
<ul id="summaryList">
<p><b> Aurhor</b>
</p>
<p>wsfwfrfrtgretryetyrtyty</p>
</ul>
......
.......
</body>
</html> (6 Replies)
Discussion started by: kheyali Mitra
6 Replies
3. Shell Programming and Scripting
Can any one give the idea on this, please.
I have the following XML file and wants to convert into CSV(comma separated value) format.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'>
<Waveset>
<Object name='ra8736'>
<Attribute name='ADDRESS'... (2 Replies)
Discussion started by: kumar04
2 Replies
4. Shell Programming and Scripting
Hi,
I have an xml file and I want to convert it with awk in to a csv file
Test.xml
<Worksheet ss:Name="Map1">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60">
<Row>
<Cell><Data... (6 Replies)
Discussion started by: research3
6 Replies
5. Programming
Hi guys,
I'm in a job of converting a restful webservice to soap. Tool for convertation uses XQuery.
Now i need to convert a message like this:
{
"firstName": "John",
"midName": null,
"lastName": "Smith",
"married": false,
"address": {
"streetAddress": "21 2nd... (5 Replies)
Discussion started by: tien86
5 Replies
6. Shell Programming and Scripting
I need to convert below xml code to csv. I searched other posts as well but this post (_https://www.unix.com/shell-programming-scripting/174417-extract-parse-xml-data-statistic-value-csv.html) gives "sed command garbled" error. As of now I have written a long script to do it, but can it be done with... (7 Replies)
Discussion started by: dineshydv
7 Replies
7. Shell Programming and Scripting
I am in need of converting billions of XML into csv file to load data to DB, i have found the below code in perl but not sure why it's not working properly.
CODE:
#!/usr/bin/perl
# Script to illustrate how to parse a simple XML file
# and pick out all the values for a specific element, in... (1 Reply)
Discussion started by: rspwilliam
1 Replies
8. Shell Programming and Scripting
Is there a Unix or Perl script that converts JSON files to CSV or tab delimited format? We are running AIX 6.1.
Thanks in advance! (1 Reply)
Discussion started by: warpmail
1 Replies
9. UNIX for Beginners Questions & Answers
This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
I am new to shell scripting, Need your help in creating a shell script which converts any unix command output to JSON format output.
example:
sample df -h command ouput :
Filesystem size used avail capacity Mounted
/dev/dsk/c1t0d0s0 8.1G 4.0G 4.0G 50% /... (13 Replies)
Discussion started by: balu1234
13 Replies