<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading JSON in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/316361#M69113</link>
    <description>&lt;P&gt;I'm so happy to be able to update this post with the answer: a &lt;A href="http://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/" target="_self"&gt;JSON libname engine is now in Base SAS 9.4&lt;/A&gt; (maint 4).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp temp;
 
/* Neat service from Open Notify project */
proc http 
 url="http://api.open-notify.org/astros.json"
 method= "GET"
 out=resp;
run;
 
/* Assign a JSON library to the HTTP response */
libname space JSON fileref=resp;
 
/* Print result, dropping automatic ordinal metadata */
title "Who is in space right now? (as of &amp;amp;sysdate)";
proc print data=space.people (drop=ordinal:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Dec 2016 19:33:03 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2016-12-02T19:33:03Z</dc:date>
    <item>
      <title>Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30036#M5703</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Is there an easy way to read JSON (JavaScript Object Notation) formatted data in SAS?&lt;BR /&gt;
&lt;BR /&gt;
-Bart</description>
      <pubDate>Mon, 08 Nov 2010 12:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30036#M5703</guid>
      <dc:creator>bheinsius</dc:creator>
      <dc:date>2010-11-08T12:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30037#M5704</link>
      <description>Hi:&lt;BR /&gt;
  That would be an easier question to answer if I knew what a JSON data file looked like. SAS can read data in a lot of different formats -- how easy it is depends on the format of the input data. Your JSON data could be in XML format and able to be read with the SAS XML LIBNAME engine or it could be "free-format" data in which case, you'd need a custom INPUT statement.&lt;BR /&gt;
 &lt;BR /&gt;
  Can you post a sample of the data here????&lt;BR /&gt;
 &lt;BR /&gt;
  And, when you are posting data, if it contains special characters, such as &amp;lt; and &amp;gt; please read this previous forum posting about how to maintain line indenting and special characters:&lt;BR /&gt;
 &lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt;&lt;BR /&gt;
              &lt;BR /&gt;
Basically, you use the [pre] and [/pre] tags around your code and data samples in order to maintain indenting and spacing.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 08 Nov 2010 15:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30037#M5704</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-11-08T15:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30038#M5705</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your answer.&lt;BR /&gt;
&lt;BR /&gt;
From wikipedia:&lt;BR /&gt;
&lt;I&gt;JSON (an acronym for JavaScript Object Notation (pronounced /dʒeɪsɔːn/)) is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript programming language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for virtually every programming language.&lt;BR /&gt;
The JSON format is often used for serializing and transmitting structured data over a network connection. It is primarily used to transmit data between a server and web application, serving as an alternative to XML.&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
An example is the following:&lt;BR /&gt;
[pre]&lt;BR /&gt;
{&lt;BR /&gt;
     "firstName": "John",&lt;BR /&gt;
     "lastName": "Smith",&lt;BR /&gt;
     "age": 25,&lt;BR /&gt;
     "address": &lt;BR /&gt;
     {&lt;BR /&gt;
         "streetAddress": "21 2nd Street",&lt;BR /&gt;
         "city": "New York",&lt;BR /&gt;
         "state": "NY",&lt;BR /&gt;
         "postalCode": "10021"&lt;BR /&gt;
     },&lt;BR /&gt;
     "phoneNumber": &lt;BR /&gt;
     [&lt;BR /&gt;
         {&lt;BR /&gt;
           "type": "home",&lt;BR /&gt;
           "number": "212 555-1234"&lt;BR /&gt;
         },&lt;BR /&gt;
         {&lt;BR /&gt;
           "type": "fax",&lt;BR /&gt;
           "number": "646 555-4567"&lt;BR /&gt;
         }&lt;BR /&gt;
     ]&lt;BR /&gt;
 }&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Do I have to write my own parser?&lt;BR /&gt;
&lt;BR /&gt;
-Bart</description>
      <pubDate>Mon, 08 Nov 2010 16:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30038#M5705</guid>
      <dc:creator>bheinsius</dc:creator>
      <dc:date>2010-11-08T16:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30039#M5706</link>
      <description>Hi:&lt;BR /&gt;
  Without knowing a LOT more about JSON, I do have some comments. It says in the Wikipedia definition that some folks use JSON format as an alternative to XML...can you get this data in XML format??? If so, you might be able to use the SAS XML Libname engine to read it.&lt;BR /&gt;
 &lt;BR /&gt;
  If not, then is there a chance you could write the dat to an HTML file?? If so, then you might be able to read the resulting HTML table with the HTTP engine for the FILENAME statement.&lt;BR /&gt;
 &lt;BR /&gt;
  It says that the JSON format is used for transmitting data between a server and a web application. What web application do you currently have receiving the JSON data?? &lt;BR /&gt;
 &lt;BR /&gt;
  I see a few issues with the data that you posted. For example -- what is the significance of the indenting??? And, what happens or how does the data look if you have more that one observation??  I can see that this particular description defines 1 "record" or 1 "observation", but what happens when you have multiple records -- what defines the end of 1 observation and the beginning of the next observation??&lt;BR /&gt;
&lt;BR /&gt;
Also, what about the address: item and the phoneNumber: item??? The indenting underneath each items eems to indicate that the items underneath address: and underneath phoneNumber: are grouped, somehow??? Additionally, there seems to be some significance to the use of the  curly brace { versus the square bracket [ -- somehow it seems like the square bracket begins a "set" of paired variables or an array definition -- I would have expected to see type1, number1, type2 and number2 -- instead of reusing type and number as variable names over again.&lt;BR /&gt;
 &lt;BR /&gt;
  It's really too bad that your variable/value pairs aren't in a form something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
firstName=John&lt;BR /&gt;
lastName=Smith&lt;BR /&gt;
age=25&lt;BR /&gt;
. . . more . . .&lt;BR /&gt;
phoneNumber_type1=home   &lt;BR /&gt;
phoneNumber_number1=212 555-1234   &lt;BR /&gt;
phoneNumber_type2=fax   &lt;BR /&gt;
phoneNumber_number2=646 555-4567&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
If they were just a bit different, then you might be able to use named INPUT, as described here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000148147.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000148147.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
You'd still need to use the variable names in the INPUT statement, so you could control the variable type, label, etc, but named INPUT would be easier.&lt;BR /&gt;
 &lt;BR /&gt;
If you parse the items yourself, I would expect that you'd read a line of input as a TEXT string and then parse out the variable and the value using SAS functions.&lt;BR /&gt;
 &lt;BR /&gt;
Can I ask why the data is in JSON format and not stored in whatever format the web application uses???&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 09 Nov 2010 00:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30039#M5706</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-11-09T00:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30040#M5707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I never saw this reply until now (email SAS Communities email notifications don't work for me).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JSON *is* the format that the web application uses; it sends serialized data to my SAS Stored Process in JSON format, I have to parse it in SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess there is no easy way, thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2012 15:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30040#M5707</guid>
      <dc:creator>bheinsius</dc:creator>
      <dc:date>2012-01-27T15:06:30Z</dc:date>
    </item>
    <item>
      <title>Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30041#M5708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no build in functionality to interpert a JSON data structure in SAS.&amp;nbsp; The recommended option is to initiate an outside utility to conver the JSON object into a XML document.&amp;nbsp; There are lots of options to do this.&amp;nbsp; There are .NET applications, perl scripts, etc...&amp;nbsp; Have the SAS Stored Process execute the necssary commands and export a more easily usable XML file.&amp;nbsp; I know there are published documents around the web showing this type of process.&amp;nbsp; I think maybe an entry in one of the SAS official Blogs.&amp;nbsp; Take a look there for additional information.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2012 21:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30041#M5708</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2012-01-27T21:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30042#M5709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestion.&lt;/P&gt;&lt;P&gt;XML isn't a handy option either, the webapp gives lots of different responses, I would have to create xmlmaps for each.&lt;/P&gt;&lt;P&gt;I was looking for something simpler, like a proc or macro that creates a SAS data set from a JSON string.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jan 2012 20:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/30042#M5709</guid>
      <dc:creator>bheinsius</dc:creator>
      <dc:date>2012-01-28T20:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/230116#M41716</link>
      <description>&lt;P&gt;Is there an easy way to read JSON (JavaScript Object Notation) formatted data in SAS? Do we have any answer for this ?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 16:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/230116#M41716</guid>
      <dc:creator>ravinsun_gmail_com</dc:creator>
      <dc:date>2015-10-15T16:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/316361#M69113</link>
      <description>&lt;P&gt;I'm so happy to be able to update this post with the answer: a &lt;A href="http://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/" target="_self"&gt;JSON libname engine is now in Base SAS 9.4&lt;/A&gt; (maint 4).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp temp;
 
/* Neat service from Open Notify project */
proc http 
 url="http://api.open-notify.org/astros.json"
 method= "GET"
 out=resp;
run;
 
/* Assign a JSON library to the HTTP response */
libname space JSON fileref=resp;
 
/* Print result, dropping automatic ordinal metadata */
title "Who is in space right now? (as of &amp;amp;sysdate)";
proc print data=space.people (drop=ordinal:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 19:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/316361#M69113</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-12-02T19:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361545#M85290</link>
      <description>&lt;P&gt;when i am running above program getting the below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The JSON engine cannot be found.&lt;BR /&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 12:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361545#M85290</guid>
      <dc:creator>arpitagarwal512</dc:creator>
      <dc:date>2017-05-25T12:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361750#M85361</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127747"&gt;@arpitagarwal512&lt;/a&gt;&amp;nbsp;- the JSON engine was added in SAS 9.4 Maint 4. &amp;nbsp;You can run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc product_status; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To see your version. &amp;nbsp;It should return something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;For Base SAS Software ...
   Custom version information: 9.4_M4
   Image version information: 9.04.01M4P110916&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2017 19:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361750#M85361</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-05-25T19:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361786#M85372</link>
      <description>can we not do end around without reinstalling newer SAS versions.</description>
      <pubDate>Thu, 25 May 2017 21:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361786#M85372</guid>
      <dc:creator>rboire</dc:creator>
      <dc:date>2017-05-25T21:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading JSON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361926#M85434</link>
      <description>&lt;P&gt;In earlier versions of SAS, you would need to simply use DATA step or &lt;A href="http://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/" target="_self"&gt;PROC DS2 to parse the JSON&lt;/A&gt;. &amp;nbsp;It's not nearly as elegant as the JSON libname engine, but for simple JSON it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-JSON/m-p/361926#M85434</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-05-26T11:35:10Z</dc:date>
    </item>
  </channel>
</rss>

