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}}
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.