将JSON嵌套到r中的数据框-非矩形

时间:2020-06-08 18:39:10

标签: r json json-api-response-converter

我有大量来自和API的JSON文件,它们的格式与我需要组合和/或转换为R中的数据帧的格式相同。我尝试了许多不同的方法来执行此操作,但是JSON文件嵌套,无法正常工作。是否有可能做到这一点?

以下是我尝试过的几个示例:

data_all <- data.frame()

for(i in 1:nrow(sov_w_add_URL)){

  response <- GET(call[i], add_headers(Authorization = "Token token=some_token_here"))
  response_txt <- content(response, "text")
  data <- fromJSON(response_txt)
  write_json(data, paste("respones",i,".json", sep=""))
}

mydata <- fromJSON(file = "respsones1.json")
mydata_table <- data.frame(mydata)

for(i in 1:nrow(sov_w_add_URL)){


  json_temp <- lapply(files, function(f) fromJSON(files = paste("respones",i, sep="")))
  json_final <- toJSON(json_temp)
  write_json(json_final, "json_final")
}

或者,我也尝试过:

data <- fromJSON(file = "respones1.json")
json_data <- as.data.frame(data)

在两种情况下,我都会遇到类似的错误:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 0

根据注释的要求,这是JSON文件:

{
risks: {
address: "431 White Rd, Willow Spring, NC, 27592",
wildfire: {
score: "B",
text: "Low"
},
wildfire_description: {
value: "Low_Dens_Intermix"
},
wildfire_risk_score: {
value: "12",
composite: 18
},
wildfire_risk: {
value: "Low"
},
wildfire_distance_to_high_area: null,
wildfire_housing_density: {
value: "46.77"
},
drought: {
score: null
},
drought_frequency_index: {
score: "C",
text: "Moderate",
pct: "43%",
desc: "447 weeks of drought over the past 20 years"
},
wildfire_history_params: {
risk: "> 1 mile from historic wildfire perimeter",
number_of_wildfires: 0,
number_of_wildfires_near: 0
},
distance_to_significant_wf_risk_params: {
risk: "Distance to significant wildfire risk",
very_high: null,
high: null,
moderate: "0"
},
fire_season_precipitation_params: {
risk: "Fire Season Precipitation",
scale: "6",
fire_season_precipitation: "22.3"
},
vegetation_burn_points: {
# of vegetation burn points within 1/2 mile: 0,
# of vegetation burn points within 1 mile: 0
},
fire_protection: {
score: "C",
text: "Outside of Municipality & > 2 & <= 3 Drive Miles from Fire Station",
aais_proxy: "PP3"
},
hh_fpc_code: {
value: "PP3"
},
hh_pfs: {
value: "HH9",
water_score: "HX4",
average_pct_loss: 0.7195,
estimated_loss_amt: 163072
},
aais_fire_protection_class_params: {
class: "PP3, PARTIALLY PROTECTED 3",
hydrant_fire_station_distance: "> 1000' from Hydrant or Hydrant not present & > 2 & <= 3 Drive Miles from Fire Station",
available_water_type: "Perennial water source < 1,000 feet? No"
},
perennial_water: {
text: "More than 1000 feet from Perennial Water",
answer: "no",
name: null
},
municipal_boundary: null,
census_block: {
geoid: "371010415022018",
state_fips_code: "37",
county_fips_code: "101",
tract: "041502",
block: "2018",
block_group: "371010415022"
},
state_county: {
state: "North Carolina",
jurisdiction: "Johnston County",
state_and_county_FIPS_code: "37101"
},
school_district: {
name: "Johnston County Schools"
},
water_type: {
value: null
},
hydrant: {
score: "D",
text: "> 1,000 feet AND <= 1,500 feet from Reported Hydrant"
},
hydrant_params: {
distance_from_nearest_hydrant: "> 1,000 feet AND <= 1,500 feet",
hydrants_within_1000_ft: 0
},
cal_fire: {
haz_code_local: "No CalFire Data",
haz_class_local: "No CalFire Data",
haz_code_state: "No CalFire Data",
haz_class_state: "No CalFire Data"
},
drive_distance_fire_station: {
distance: 2.61,
units: "miles"
},
drive_time_fire_station: {
duration: 5,
units: "minutes"
},
fire_station_type: {
value: "Blended"
},
number_of_fire_stations_within_10_miles: 11,
number_of_fire_stations_within_5_miles: 4,
nearest_fire_station: {
title: "Fifty Two Ten Fire Department Station 2",
lat: 35.56021,
lng: -78.63659,
type: "Blended",
response_area: "Fifty - Two Ten Fire Zone",
units: "miles",
distance: 2.28,
drive_distance_fire_station: {
distance: 2.61,
units: "miles"
},
drive_duration_value: 5,
drive_duration_units: "minutes"
},
nearest_fire_station_2: {
title: "Fifty Two Ten Fire Department Station 1",
lat: 35.51218,
lng: -78.57952,
type: "Blended",
response_area: "Fifty - Two Ten Fire Zone",
units: "miles",
distance: 3.09,
drive_distance_fire_station: {
distance: 3.91,
units: "miles"
},
drive_duration_value: 6,
drive_duration_units: "minutes"
},
nearest_fire_station_3: {
title: "West Johnston Fire Department",
lat: 35.48008,
lng: -78.60882,
type: "Blended",
response_area: "West Johnston Fire Zone",
units: "miles",
distance: 3.54,
drive_distance_fire_station: {
distance: 5.2,
units: "miles"
},
drive_duration_value: 9,
drive_duration_units: "minutes"
},
fault_earthquake: {
score: null,
text: ""
},
fracking_earthquake: {
score: null,
text: ""
},
designated_fault: {
score: null
},
earthquake: {
score: "A",
text: "No Damage",
MMI: "4",
shake: "Light",
richter_scale: "2.8 - 3.4"
},
mudslide_risk: {
score: null
},
lava_flow: {},
tsunami: {
score: null,
text: ""
},
hurricane: {
score: null
},
superfund: {
score: null
},
brownfield: {
score: null
},
sinkhole: {
score: null
},
sinkhole_ring_params: {
ring_0_1_mile: 0,
cummulative_0_1_mile: 0,
ring_1_2_mile: 0,
cummulative_0_2_mile: 0,
ring_2_3_mile: 0,
cummulative_0_3_mile: 0,
ring_3_4_mile: 0,
cummulative_0_4_mile: 0,
ring_4_5_mile: 0,
cummulative_0_5_mile: 0
},
sinkhole_risk_params: {
sinkhole_susceptibility_grade: "D",
sinkhole_susceptibility_risk: "High Risk of Sinkhole Occurrence",
karst_type: "Unconsolidated calcareous or carbonate rocks at or near the land surface in a humid climate",
climate: "humid",
rocktype: "Sand",
closed_depression_grade: null,
closed_depression_risk: null,
sinkhole_point_grade: null,
sinkhole_distance: null
},
wind: {
score: "F",
text: "Very High"
},
wind_per_decade: {
value: "23"
},
enhanced_wind_params: {
score: "D",
text: "High",
scale: 43,
historical_wind_events: {
wind_rad: "95% chance of damaging wind occurrence in 10 years in a 1.17 mile radius"
},
num_of_damaging_wind_incidents_within_25_miles_since_1996: 712,
count_within_25_miles_for_last_decade: 457,
nearest_wind_incident: {
year: "2017",
type: "Thunderstorm Wind",
injuries: "0",
deaths: "0",
prop_dam: "0.50K",
crop_dam: "0.00K",
wind_spd: "50",
distance_miles: 2.16
},
waddrisk: 0.013355,
wpctrisk: "1.3355%"
},
hail: {
score: "F",
text: "Very High"
},
hail_per_decade: {
value: "47"
},
enhanced_hail_params: {
score: "C",
text: "Moderate",
scale: 41,
historical_hail_events: {
hail_rad: "95% chance of damaging hail occurrence in 10 years in 2.1 mile radius"
},
num_of_damaging_hail_incidents_within_25_miles_since_1996: 397,
count_within_25_miles_for_last_decade: 142,
nearest_hail_incident: {
year: "2008",
type: "Hail",
injuries: "0",
deaths: "0",
prop_dam: "0.00K",
crop_dam: "0.00K",
inches: "1",
distance_miles: 1.26
},
haddrisk: 0.00744,
hpctrisk: "0.744%"
},
convection_storm: {
score: "F",
text: "Very High"
},
convection_storm_per_decade: {
value: "234"
},
tornado: {
score: "D",
text: "High"
},
tornado_per_decade: {
value: "16"
},
enhanced_tornado_params: {
score: "C",
text: "Moderate",
scale: 37,
historical_tornado_events: {
tornado_rad: "50% chance of damaging tornado occurrence in 10 years in 5.33 mile radius"
},
num_of_damaging_tornado_incidents_within_25_miles_since_1996: 40,
count_within_25_miles_for_last_decade: 22,
nearest_tornado_incident: {
year: "2004",
type: "Tornado",
injuries: "0",
deaths: "0",
prop_dam: "5K",
crop_dam: "N/R",
fscale: "F1",
distance_miles: 5.5
},
taddrisk: 0.002932,
tpctrisk: "0.2932%"
},
lightning: {
score: "D",
text: "High"
},
lightning_yr: {
value: ">11 AND <=14"
},
enhanced_lightning_params: {
score: "C",
text: "Moderate",
scale: 44,
lsqmi: "95% chance of 20.203503 ground strikes in 1 year per square mile",
laddrisk: 0.03157,
lpctrisk: "3.1568%",
strikes_yr: "6343 ground lightning strikes within 10 miles last year"
},
weather_params: {
annual_average_days_less_than_0: "0.1 Days",
annual_average_days_less_than_10: "0.9 Days",
annual_average_days_less_than_20: "13.8 Days",
annual_average_days_more_than_40: "351.7 Days",
annual_average_days_more_than_50: "321.1 Days",
annual_fall_days_less_than_0: "0.0 Days",
annual_fall_days_less_than_10: "0.0 Days",
annual_fall_days_less_than_20: "0.4 Days",
annual_fall_days_less_than_32: "9.9 Days",
annual_spring_days_less_than_0: "0.0 Days",
annual_spring_days_less_than_10: "0.0 Days",
annual_spring_days_less_than_20: "0.4 Days",
annual_spring_days_less_than_32: "11.5 Days",
annual_winter_days_less_than_0: "0.1 Days",
annual_winter_days_less_than_10: "0.9 Days",
annual_winter_days_less_than_20: "13.0 Days",
annual_winter_days_less_than_40: "78.2 Days",
average_annual_precipitation: "46.4 Inches",
average_annual_temperature_max: "71.3 Degrees F",
average_annual_temperature_min: "47.9 Degrees F",
avg_num_days_below_32_degrees: "2.2 Days",
avg_num_winter_days_below_32_degrees: "58.7 Days",
cooling_degree_days: "1573.0 Degrees F",
fall_diurnal_range: "23.7 Degrees F",
fall_days_with_max_temp_less_than_32: "0.0 Days",
heating_degree_days: "3540.0 Degrees F",
spring_days_with_max_temp_less_than_32: "0.1 Days",
spring_diurnal_range: "25.4 Degrees F",
winter_days_with_max_temp_less_than_32: "2.1 Days",
winter_diurnal_range: "23.8 Degrees F",
average_annual_snowfall: "2.6 Inches",
average_days_snowfall_greater_than_10_inches: "0.0 Days",
average_days_snowfall_greater_than_1_inch: "0.9 Days",
average_fall_snowfall: "0.0 Inches",
average_spring_snowfall: "0.1 Inches",
average_winter_snowfall: "2.5 Inches",
avg_days_snow_depth_above_10_in: "0.0 Days",
avg_days_snowfall_above_1_in: "0.9 Days",
fall_days_snow_depth_greater_than_10_inches: "0.0 Days",
fall_days_snow_depth_greater_than_1_inch: "0.0 Days",
fall_days_snow_depth_greater_than_3_inches: "0.0 Days",
fall_days_snow_depth_greater_than_5_inches: "0.0 Days",
spring_days_snow_depth_greater_than_10_inches: "0.0 Days",
spring_days_snow_depth_greater_than_1_inch: "0.0 Days",
spring_days_snow_depth_greater_than_3_inches: "0.0 Days",
spring_days_snow_depth_greater_than_5_inches: "0.0 Days",
winter_days_snow_depth_greater_than_10_inches: "0.0 Days",
winter_days_snow_depth_greater_than_1_inch: "0.9 Days",
winter_days_snow_depth_greater_than_3_inches: "0.4 Days",
winter_days_snow_depth_greater_than_5_inches: "0.0 Days"
},
hardiness: {
avextmin: "10 to 20 F",
zone: "8",
avextmin5: "10 to 15 F",
zoneseg: "8a"
},
mold_index: {
index: 3863.7,
score: "D",
text: "High"
},
ice_dam_index: {
index: 79,
score: "B",
text: "Low"
},
frozen_pipe_index: {
index: 73.9,
score: "B",
text: "Low"
},
hh_snow_load: {
score: "A",
text: "None",
desc: "Zero chance of structural roof failure due to snow load",
scale: 0
},
potential_maximum_precipitation: "9.99 Inches",
hazardhub_flood: {
score: "A",
text: "Very Low risk of damage from stream/river flooding."
},
hazardhub_flood_params: {
dist: 3143,
elevnff: 222,
elev_pt: 301,
diff: 79,
lines_distance: 3143,
lines_diff: 79,
lines_score: "A",
lines_name: null,
lines_descrip: "Intermittent stream, river, or wash",
polygons_distance: 3742,
polygons_diff: 60,
polygons_score: "A",
polygon_type: "LAKE/POND/RESERVIOR",
polygon_name: "Pond",
polygon_descrip: "Perennial lake or pond"
},
fema_all_flood: {
score: "B",
text: "Covered by FEMA digital maps. Minimal to No Risk of Flooding"
},
fema_all_flood_params: {
dfirm_id: "37101C",
version_id: "2.3.3.2",
fld_ar_id: "37101C_1210",
study_typ: "NP",
fld_zone: "X",
zone_subty: "AREA OF MINIMAL FLOOD HAZARD",
sfha_tf: "F",
static_bfe: -9999,
v_datum: null,
depth: -9999,
len_unit: null,
velocity: -9999,
vel_unit: null,
ar_revert: null,
ar_subtrv: null,
bfe_revert: -9999,
dep_revert: -9999,
dual_zone: null,
source_cit: "37101C_STUDY63"
},
distance_to_significant_flood_params: {
distance_to_100yr_floodplain: null,
elevation_in_feet: {
value: 301.28
},
elevation100: null,
elevation_difference_100: null
},
fema_firm_date: {
cid: "370138",
name: "JOHNSTON COUNTY",
type: "COUNTY OF",
initial_flood_hazard_bounday_map_id_date: "1975-01-03",
initial_firm_id_date: "1983/09/30",
current_effective_date_flood_map: "2018/06/20",
date_entered_program: "1983/09/30",
community_name: "N/A",
crs_entry_date: "N/A",
current_effective_date: "N/A",
current_class: "N/A",
percent_discount_for_sfha: "N/A",
percent_discount_for_non_sfha: "N/A",
status: "N/A"
},
base_flood_elevation: {
text: "1.376 MILES from BFE = 197 feet",
meter: 2214,
distance: {
value: 1.375949656396224,
units: "miles"
},
elevation: {
value: 197,
units: "feet"
}
},
cbrs_params: {
designation: "OUT",
unit: null,
cbrs_type: null,
fi_date: null,
su_date: null,
name: null,
fast_acres: null,
wet_acres: null,
shore_mile: null
},
fema_claims: {
1999: 0,
2000: 0,
2001: 0,
2002: 0,
2003: 0,
2004: 0,
2005: 0,
2006: 0,
2007: 0,
2008: 0,
2009: 0,
2010: 0,
2011: 0,
2012: 0,
2013: 0,
2014: 0,
2015: 0,
2016: 0,
2017: 0,
2018: 0,
total: 0
},
hh_elevation: {
slope: "1.08 degrees",
aspect: "349.74 degrees",
elevation: "301.28 feet"
},
elevation_in_feet: {
value: 301.28
},
aspect_risk: {
aspect: "349.74 degrees",
score: "A",
direction: "North"
},
slope_risk: {
slope: "1.08 degrees",
score: "A",
description: "Flat to Very Low"
},
wind_pool: {
score: null
},
wind_region: {
score: null,
text: null,
text2: null
},
wind_born_debris: {
score: null,
text: ""
},
mine_subsidence: {
score: null,
text: ""
},
surge_max: {
score: "N/A",
text: "N/A",
potential_inundation_level: "N/A",
category: "N/A"
},
coast_distance: {
distance: 84.46,
units: "miles",
high_res_distance: {
value: 84.46,
units: "miles"
},
low_res_distance: {
value: 68.21,
units: "miles"
},
beach_distance: {
value: 98.05,
units: "miles"
}
},
murder: {
score: "B",
text: "Low murder rate",
value: 56
},
forcible_rape: {
score: "A",
text: "Very low forcible rape rate",
value: 24
},
forcible_robbery: {
score: "B",
text: "Low forcible robbery rate",
value: 57
},
aggravated_assault: {
score: "A",
text: "Very low aggravated assault rate",
value: 21
},
burglary: {
score: "C",
text: "Average burglary rate",
value: 97
},
larceny: {
score: "A",
text: "Very low larceny rate",
value: 40
},
motor_vehicle_theft: {
score: "A",
text: "Very low motor vehicle theft rate",
value: 40
},
crime: {
score: "B",
text: "Low crime rate",
value: 48
},
airport_noise: {
decibels: null,
score: null,
text: null
},
radon: {
score: "B",
text: "Predicted average indoor radon screening levels less than 2 pCi/L"
},
landslide: {
score: null
},
re_tier_counties: {
value: null
},
premium_tax: {
value: true
},
premium_tax_params: {
prem_hh_id: {
value: "HH_5626"
},
fips: {
value: "3710100000"
},
county: {
value: "Johnston"
},
city: {
value: null
},
city_des: {
value: null
},
auth_ta: {
value: "Johnston County"
},
fips_ta: {
value: "3710100000"
},
fire_zone: {
value: null
},
tax_cd_1: {
value: null
},
tax_cd_2: {
value: null
},
dt_vint: {
value: "012018"
},
gnis: {
value: "1026327"
}
},
premium_tax_ky: {
value: false
},
premium_tax_ky_params: {},
ust: {
score: null
},
ust_nearest: {},
ust_tanks_num_in_quarter_mile_radius: {
value: null
},
ust_tanks_num_in_half_mile_radius: {
value: null
},
ust_tanks_num_in_1_mile_radius: {
value: null
},
ust_nearest_leaking: {},
ust_facilities_leaking_quarter_mile_radius: {
value: null
},
nuclear_site: {
score: "D",
text: "High"
},
nuclear_site_nearest: {
distance: {
value: 19.56,
units: "miles"
},
name: {
value: "Shearon Harris"
},
type: {
value: "Power Plant"
},
reactors: {
value: "1"
}
},
volcano: {
score: null
},
volcano_nearest: {},
drug_alcohol_deaths: {
score: "B",
text: "LOW"
},
drug_alcohol_deaths_deaths: {
value: "1491"
},
drug_alcohol_deaths_score: {
value: "LOW"
},
drug_alcohol_deaths_rate100k: {
value: "778.8"
},
toxic_release_facilities: {
score: null
},
toxic_release_facilities_params: {},
clandestine_lab: {
address: "14825 210 Highway",
city: "Angier",
state: "NC",
zip: "27501",
date: "5/14/2009",
distance: "1.65 miles",
number_within_5_miles: 7
},
police_stations: {
name: "Angier Police Department",
distance: "6.22 miles",
number_within_5_miles: 0
},
tx_codes: null,
fl_codes: null,
fl_construction_line: "OUT",
hospital: {
distance: null,
number_of_hospitals_within_5_miles: 0,
number_of_hospitals_within_10_miles: 0
},
urgent_care: {
name: "EDGEWATER MEDICAL CENTER",
address: "511 NORTH RALEIGH STREET SUITE B",
state: "NC",
type: "URGENT MEDICAL CARE CENTER",
distance: "6.21 miles"
},
lat: 35.5277123,
lng: -78.6313815,
state: "NC",
location_type: "ADDRESS",
match_level: "houseNumber",
google_maps_url: https://www.google.com/maps/search/?api=1&query=35.527712,-78.631382
},
enhanced_property_data: {
property: {
address: "530 WHITE MEMORIAL CHURCH RD, WILLOW SPRING, NC 27592",
apn: "13C03023",
owner: "RALPH S HONEYCUTT REVOCABLE LIVING TRUST",
street_address: "530 WHITE MEMORIAL CHURCH RD",
use_code: "Single Family Residence",
zip: "27592"
},
assessment: {
Air_Conditioning: "None",
Air_Conditioning_Type: null,
Amenities: "Mobile Home Hookup",
Amenities_2: null,
Assessed_Improvement_Value: 44530,
Assessed_Land_Value: 757780,
Assessment_Year: "2019",
Assessors_Parcel_Number: "13C03023",
Basement: null,
Building_Area: 1125,
Building_Area_1: 1125,
Building_Class: null,
Building_Condition: null,
Building_Quality: "C-",
Condo_Project_Bldg_Name: null,
Current_Owner_Name: "RALPH S HONEYCUTT REVOCABLE LIVING TRUST",
Fireplace: null,
Garage_Cars: 0,
Garage_Type: "Garage",
Heating: "Forced air unit",
LSale_Document_Number: null,
LSale_Price: null,
LSale_Price_Code: null,
LSale_Recording_Date: null,
LValid_Price: null,
Legal_Brief_Description_FULL: "DIST:13 LONG BRANCH 161400-76",
Legal_Subdivision_Name: null,
LotSize_Acres: 43,
LotSize_Depth_Feet: "0",
LotSize_Frontage_Feet: null,
LotSize_Square_Feet: 1873080,
Main_Building_Area_Indicator: "Living Area",
N_of_Plumbing_Fixtures: null,
Neighborhood_Code: "158",
No_of_Buildings: 0,
No_of_Stories: "1",
Number_of_Baths: 1,
Number_of_Bedrooms: 2,
Number_of_Partial_Baths: 0,
Number_of_Units: 0,
Owner1FirstName: null,
Owner1LastName: "RALPH S HONEYCUTT REVOCABLE LIVING TRUST",
Owner2Firstname: null,
Owner2LastName: null,
Owner_Occupied: null,
PSale_Price: null,
Pool: null,
Roof_Cover: "Metal",
Roof_Type: "GABLE OR HIP",
School_Tax_District_1: "38",
School_Tax_District_1_Indicator: "Fire",
School_Tax_District_2: "13",
School_Tax_District_2_Indicator: "Municipality",
School_Tax_District_3: null,
School_Tax_District_3_Indicator: null,
Site_Influence: null,
Standardized_Land_Use_Code: "Single Family Residential",
Tax_Amount: 6599.95,
Tax_Delinquent_Year: null,
Tax_Rate_Code_Area: "C,FR38",
Topography: null,
Total_Assessed_Value: 802310,
Total_Market_Value: 802310,
Total_Number_of_Rooms: "0",
Type_Construction: null,
Year_Built: "1900",
tax_marketvalue: 802310
},
mls_listing_record_details: {},
listing_record: {},
mortgage_info: {
Current_Est_LTV_Combined: "0.0000",
Mtg01_Curr_Est_Bal: null,
Mtg01_Loan_Amount: null,
Mtg01_Title_Company_Name: null,
Mtg01_lender_name_beneficiary: null,
Mtg01_loan_type: null,
Total_Open_Lien_Balance: null
},
valuation: {
price_range_max: 926541,
price_range_min: 791663
},
images: []
}
}

0 个答案:

没有答案
相关问题