The following examples communicate with the National Aeronautics and Space Administration (NASA) API. You must request a key from https://api.nasa.gov/index.html#apply-for-an-api-key and assign it to the key variable to run the scripts successfully.
url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
data = request << Send();
Write( data );
{"results":[["59fa04859600022b4d2e076f","LAR-TOPS-48","All-Organic Electroactive Device","NASA's Langley Research Center offers you an all-organic electroactive device system fabricated with single-wall carbon nanotube (SWCNT)....}
// JSON output written to the log
Notes:
• The query string is at the end of the URL, following “?”. For example, in https://www.google.com/search?q=jmp, “q=jmp” is the query string. New HTTP Request() automatically URI-encodes key/value pairs in a query string (and FORM).
• When you put an associative array in either a query string or a form, the key/value pairs get URI encoded. Spaces, ampersands, and other characters get encoded to ASCII, and the ampersand is escaped. The encoding is a “%” encoding.
• The web service defines the valid key/value pairs that it accepts. Refer to the API documentation for valid key/value pairs.
url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
json = request << Send();
jsl_json = Parse JSON( json );
// turns JSON data into a JSL associative array
results = jsl_json["results"];
Write( results );
{{"59fa04859600022b4d2e076f", "LAR-TOPS-48", "All-Organic Electroactive Device", "NASA's Langley Research Center offers you an all-organic electroactive device system fabricated with single-wall carbon nanotube (SWCNT)....}}
// associative array
url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
json = request << Send();
jsl_json = Parse JSON( json );
json = As JSON Expr( jsl_json["results"] );
dt = JSON To Data Table(
json,
JSON Settings(
Stack( 0 ),
Col(
"/root",
Column Name( "root" ),
Fill( "Use Once" ),
Type( "Pandas Values" ),
Format( {"Best"} ),
Modeling Type( "Continuous" )
)
)
);
dt << Set Name( "NASA Patents" );
Figure 14.5 Data Imported in a Data Table