Date: Fri, 27 Aug 2010 12:46:22 -0600
Reply-To: Alan Churchill <alan.churchill@SAVIAN.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Alan Churchill <alan.churchill@SAVIAN.NET>
Subject: Re: Reading in JSON format with SAS
Content-Type: text/plain; charset="us-ascii"
.NET also has a library for handling JSON and XML (to and from).
Alan
Alan Churchill
Savian
Work: 719-687-5954
Cell: 719-310-4870
-----Original Message-----
From: Chang Chung [mailto:chang_y_chung@HOTMAIL.COM]
Sent: Friday, August 27, 2010 7:57 AM
Subject: Re: Reading in JSON format with SAS
On Thu, 26 Aug 2010 17:35:18 -0400, John C. Munoz <johncmunoz@GMAIL.COM>
wrote:
...
>I've been toying around quite a bit with lots of APIs lately and using SAS'
>xml parser and xml libname engine to help me process lots of great data.
>
>Now I'm stuck with an API which provides only JSON formatted data. I
>could probably parse it in the data step, but it looks like a real pain
>in the neck. Is anyone aware of an easier way to bring JSON formatted
>data into SAS, or convert the JSON formatted data into a format that
>SAS can work
with?
...
Hi, John:
This is kind of OT: I would convert json to xml using javascript, then read
the resulting xml doc into sas. If you are using jQuery, there is even a
plugin called (what else?) json2xml, and the conversion takes a single line
of code. The only thing is that javascript running inside a browser cannot
write to a file (which would be a huge security risk!), but there are many
ways to get the page content out.
It would be interesting to write a json to xml (and from xml to json)
converter in sas (or in sas macro) -- it will be somewhat cumbersome but not
impossible.
Cheers,
Chang
test.html
----------------------------------------------------------
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script src="http://plugins.jquery.com/files/jquery.json2xml.js_1.txt"></
script>
<script>
var json= {
student: [
{name: 'Alfred', sex: 'M', age: 14},
{name: 'Alice', sex: 'F', age: 13},
{name: 'Barbara', sex: 'F', age: 13}] };
$(function() {
$('#xml').val($.json2xml(json, {formatOutput: true})); }); </script>
</head> <body> <textarea cols="50" rows="5" id="xml"></textarea> </body>
</html>
----------------------------------------------------------
opened in a browser shows the following in a textbox
----------------------------------------------------------
<root>
<student name="Alfred" sex="M" age="14"/>
<student name="Alice" sex="F" age="13"/>
<student name="Barbara" sex="F" age="13"/> </root>
----------------------------------------------------------
|