# Help parsing JSON for Notebook of Latest COVID-19 Papers

**URL:** https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944
**Category:** Help
**Created:** [March 16, 2020, 3:41pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944 "2020-03-16T15:41:33Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 3:41pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/1 "2020-03-16T15:41:33Z")

</div>

Hi, I’m having trouble parsing the JSON output from this page (list of latest papers on COVID-19): [http://connect.biorxiv.org/relate/content/181](http://connect.biorxiv.org/relate/content/181)

in this notebook: [https://observablehq.com/@ismms-himc/covid-19-sars-cov-2-preprints-from-medrxiv-and-biorxiv](https://observablehq.com/@ismms-himc/covid-19-sars-cov-2-preprints-from-medrxiv-and-biorxiv)

I’m trying to adapt from the example [https://observablehq.com/@jashkenas/earthquakes](https://observablehq.com/@jashkenas/earthquakes)

Any help would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)
#### Post date: [March 16, 2020, 3:46pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/2 "2020-03-16T15:46:05Z")

</div>

Those don’t appear to be CORS-accessible APIs, so you’ll either need to download the JSON and attach it to your notebook as a file, or you’ll needs a [CORS proxy](https://github.com/Rob--W/cors-anywhere) to make them accessible. (Or you can write bioRxiv and ask them to [enable CORS](https://enable-cors.org/).)

---

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 3:52pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/3 "2020-03-16T15:52:54Z")

</div>

Thanks, that makes sense!

---

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 6:22pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/4 "2020-03-16T18:22:33Z")

</div>

Hi @mbostock, Biorxiv got back to me but they wanted clarification. I’m paraphrasing below:

“Can you please help us understand what exactly the JSON feed for our COVID-19 does not do relative to what you are trying to accomplish? What kind of auto-updating are you trying to do that cannot be done by loading the JSON feed as it is? Please help us understand what you need.”

This was my response

"  
Thanks for getting back to me. As far as I understand we want to have cross origin requests from the URL [http://connect.biorxiv.org/relate/collection\_json.php?grp=181](http://connect.biorxiv.org/relate/collection_json.php?grp=181)

The page is blocking our front-end requests. Would you be able to ask for clarification on the discourse page ([Help parsing JSON for Notebook of Latest COVID-19 Papers](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944)) so Mike could clarify? I’m happy to paraphrase your question. "

As far as I understand their site just needs to allow for cross origin requests but I’m not sure if I’m missing something. Thanks for your help!

---

<div class="post-metadata">

### Author: ![radames](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/radames/32/1699_2.png) [@radames](https://talk.observablehq.com/u/radames)
#### Post date: [March 16, 2020, 6:33pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/5 "2020-03-16T18:33:51Z")

</div>

You can send them the server recipes on how to enable CORS [https://enable-cors.org/server.html](https://enable-cors.org/server.html)  
very important the header shall allow everywebsite

`'Access-Control-Allow-Origin' '*';`

ps. meanwhile you could use [https://cors-anywhere.herokuapp.com/](https://cors-anywhere.herokuapp.com/) on your notebook

```auto
url = "https://cors-anywhere.herokuapp.com/https://connect.biorxiv.org/relate/collection_json.php?grp=181"`

```

---

<div class="post-metadata">

### Author: ![radames](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/radames/32/1699_2.png) [@radames](https://talk.observablehq.com/u/radames)
#### Post date: [March 16, 2020, 6:57pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/6 "2020-03-16T18:57:49Z")

</div>

@cornhundred actually I just look your notebook and seems like the requests to to [biorxiv.org](http://biorxiv.org) is working with CORS enable, however the JSON response is coming with a weird JSON format start and ending with **()** parenthesis

![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/e/ed437aa6a0656d412c900e2ced9c0bf2547ac054.png)

So if you fetch is as a text and remove the parenthesis, then you can JSON parse the string

here is how a did

> **[COVID-19 SARS-CoV-2 preprints from medRxiv and bioRxiv](https://observablehq.com/d/1794a6f3f8c5fcb9)**
>
> An Observable notebook by Radamés Ajna.

```auto
data = d3.text(url).then(text => JSON.parse(text.substring(1, text.length - 1)))

```

---

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 7:00pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/7 "2020-03-16T19:00:55Z")

</div>

> [@cornhundred](#):
>
> [bioRxiv COVID-19 SARS-CoV-2 preprints from medRxiv and bioRxiv](http://connect.biorxiv.org/relate/content/181)

Thanks @radames!

---

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 8:02pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/8 "2020-03-16T20:02:45Z")

</div>

I have another related question (really just a Javascript mapping question I think). So now I have an array of arrays `data` (one for each paper) and the first element of each sub-array contains the object of interest (information on the specific paper). However, I need to make a new array of that assembles the objects into a single array so I can visualize as a table (e.g. [https://observablehq.com/@tmcw/fancy-tables](https://observablehq.com/@tmcw/fancy-tables)).

I tried something like `clean_data = data.map(x=>x[0])` but I was getting the error `cannot read property '0' of null`

If I try to visualize using `renderTable(data[0])` I’m only able to see a single row - since I’m only giving a single array element, including `data` fails since it is an array of single-length arrays.

---

<div class="post-metadata">

### Author: ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)
#### Post date: [March 16, 2020, 8:22pm UTC](https://talk.observablehq.com/t/help-parsing-json-for-notebook-of-latest-covid-19-papers/2944/9 "2020-03-16T20:22:07Z")

</div>

I figured it out. One of the array elements must have been null, so now I just ran data.filter and data.map. Thanks all for the help!
