I'm trying to import the FEMA disaster areas using their JSON api. Proc HTTP completes with status code 200 (normal) but the libname statement returns an error that i can't trace. Column 567 is in the middle of the first record and doesn't appear to have invalid characters. Any ideas on where to look?
ERROR: Invalid JSON in input near line 1 column 567: Unexpected characters found after valid JSON text.
ERROR: Error in the LIBNAME statement.
filename resp temp;
proc http
url = "https://www.fema.gov/api/open/v1/DisasterDeclarationsSummaries.json"
method = "get"
out = resp;
run;
libname res json fileref=resp;
I had a look.
This file is a suite of { } groups, with no overall structure. It's invalid jason.
You need to add an overall structure to go from
{"disasterNumber":1}{"disasterNumber":3}
to something like:
{"event1":{"disasterNumber":1},"event2":{"disasterNumber":3}}
What does this generate?
data _null_;
infile RESP lrecl=600;
input;
A= rank(char(_infile_,567)) ;
putlog '~' _N_ '~' A '~' ;
if _N_=10 then stop;
run;
~1 ~123 ~
123 is the opening curly bracket {.
So that's a valid character.
The issue must therefore be the structure of the JSON file.
Save the file as a text file and look at how it is broken when opening a new { } block at that position.
I've changed to thread tile to json library unexpected character from json library invalid character
I had a look.
This file is a suite of { } groups, with no overall structure. It's invalid jason.
You need to add an overall structure to go from
{"disasterNumber":1}{"disasterNumber":3}
to something like:
{"event1":{"disasterNumber":1},"event2":{"disasterNumber":3}}
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.