1

I'm trying to import data in R using api link.

Here is my API link: Link

Here is glimpse of data

{"DataID":"311","Question":"Health facility code","Answer":"2555","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"311","Question":"Health facility code","Answer":"2555","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"310","Question":"Disease severityy","Answer":"UM,VM","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"310","Question":"Disease severityy","Answer":"UM,VM","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"309","Question":"Type of malariaa","Answer":"PF,PV","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"309","Question":"Type of malariaa","Answer":"PF,PV","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"308","Question":"Mode of diagnosisss","Answer":"RDT","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"308","Question":"Mode of diagnosisss","Answer":"RDT","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"307","Question":"Patient age","Answer":"50","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"307","Question":"Patient age","Answer":"50","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:47 pm"}{"DataID":"306","Question":"Patient sex","Answer":"Male","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:46 pm"}{"DataID":"306","Question":"Patient sex","Answer":"Male","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:46 pm"}{"DataID":"305","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:46 pm"}{"DataID":"305","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"7701049","Date":"2022-01-07, 2:46 pm"}{"DataID":"304","Question":"Health facility code","Answer":"2555","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"303","Question":"Disease severityy","Answer":"UM,SM","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"302","Question":"Type of malariaa","Answer":"PF,Mixed","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"301","Question":"Mode of diagnosisss","Answer":"Microscopy","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"300","Question":"Patient age","Answer":"50","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"299","Question":"Patient sex","Answer":"Female","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"298","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"3278221","Date":"2022-01-07, 2:44 pm"}{"DataID":"293","Question":"Health facility code","Answer":"4500","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"292","Question":"Disease severityy","Answer":"UM,SM","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"291","Question":"Type of malariaa","Answer":"PF,Mixed","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"290","Question":"Mode of diagnosisss","Answer":"RDT","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"289","Question":"Patient age","Answer":"40","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"288","Question":"Patient sex","Answer":"Male","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"287","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"4169191","Date":"2022-01-07, 2:15 pm"}{"DataID":"274","Question":"Health facility code","Answer":"222","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"273","Question":"Disease severityy","Answer":"UM,SM","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"272","Question":"Type of malariaa","Answer":"PF,PV","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"271","Question":"Mode of diagnosisss","Answer":"RDT","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"270","Question":"Patient age","Answer":"21","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"269","Question":"Patient sex","Answer":"Male","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"268","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"2926181","Date":"2021-12-11, 3:30 am"}{"DataID":"267","Question":"Health facility code","Answer":"1250","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"266","Question":"Disease severityy","Answer":"UM,VM","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"265","Question":"Type of malariaa","Answer":"PV,Mixed","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"264","Question":"Mode of diagnosisss","Answer":"Microscopy","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"263","Question":"Patient age","Answer":"50","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"262","Question":"Patient sex","Answer":"Female","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}{"DataID":"261","Question":"Patient residence code","Answer":"Union","Status":"Approved","Verify_code":"8883179","Date":"2021-12-07, 3:01 pm"}

Now, I want to import this data using api link as dataframe in R.

1 Answer 1

2
lnk <- readLines('https://malariaapitracker.com/web/api/http/http.php?id=21')
jsonlite::fromJSON(sprintf('[%s]', gsub('}{', '},{', lnk, fixed = TRUE)))

   DataID               Question     Answer   Status Verify_code                Date
1     311   Health facility code       2555 Approved     7701049 2022-01-07, 2:47 pm
2     311   Health facility code       2555 Approved     7701049 2022-01-07, 2:47 pm
3     310      Disease severityy      UM,VM Approved     7701049 2022-01-07, 2:47 pm
4     310      Disease severityy      UM,VM Approved     7701049 2022-01-07, 2:47 pm
5     309       Type of malariaa      PF,PV Approved     7701049 2022-01-07, 2:47 pm
6     309       Type of malariaa      PF,PV Approved     7701049 2022-01-07, 2:47 pm
7     308    Mode of diagnosisss        RDT Approved     7701049 2022-01-07, 2:47 pm
8     308    Mode of diagnosisss        RDT Approved     7701049 2022-01-07, 2:47 pm
9     307            Patient age         50 Approved     7701049 2022-01-07, 2:47 pm
:
:
:
Sign up to request clarification or add additional context in comments.

1 Comment

It shows error on my side. Error: parse error: invalid object key (must be a string) [{] [ "Date": "2021-12-07, 3:0 (right here) ------^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.