# FetchJson from FuseJS doesn't accept Array as root element(?)

**URL:** https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721
**Category:** Bug Reports
**Created:** [July 8, 2015, 10:13pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721 "2015-07-08T22:13:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tri\_Nguyen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/tri_nguyen/32/540_2.png) [@Tri\_Nguyen](https://forums.fusetools.com/u/Tri_Nguyen)
#### Post date: [July 8, 2015, 10:13pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721/1 "2015-07-08T22:13:43Z")

</div>

Hi!

I tried displaying data from a data source serving JSON with an array as the root element. This resulted in a list with _one_ (empty?) element when displaying it in the list. JavaScript code:

```javascript
var FetchJson = require("FuseJS/FetchJson");

module.exports = {
  dataSource: FetchJson("http://nodeit.no/array.json")
};

```

Snip of the .UX code:

```auto
<Each Items="{dataSource}">
  <Header Value="{Title}" />
  <Article Value="{Summary}" />  
  <PublishedDate Value="{PublishDate}" />
</Each>

```

Example data:

- The data as an object: [http://nodeit.no/object.json](http://nodeit.no/object.json)
- The same data with array as the root: [http://nodeit.no/array.json](http://nodeit.no/array.json)

I then tried wrapping the same data inside an object, with luck. The elements was displaying inside the list by using the `object.json`, and changing the `Items="{datasource}"` to `Items="{datasource.data}"`

Have I overlooked something? 🙂

**EDIT:**

When printing the **{dataSource}** using **array.json** I get a **Fuse.Reactive.AsyncArray**.

When printing the same using **object.json** I get **Fuse.Reactive.AsyncObject**. Trying to print **{dataSource.data}** from **object.json** gives **Fuse.Reactive.AsyncArray**.

---

<div class="post-metadata">

### Author: ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)
#### Post date: [July 8, 2015, 11:13pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721/2 "2015-07-08T23:13:34Z")

</div>

Hi!

It’s hard to say what’s going on here without seeing how the data source is structured. For some reasons I can’t get your links to work 😕

---

<div class="post-metadata">

### Author: ![Tri\_Nguyen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/tri_nguyen/32/540_2.png) [@Tri\_Nguyen](https://forums.fusetools.com/u/Tri_Nguyen)
#### Post date: [July 8, 2015, 11:23pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721/3 "2015-07-08T23:23:47Z")

</div>

Ouch. I’ve probably hardocded the server IP on my machine and forgot to update the DNS. Try these instead (with the correct IP) 😃

- [http://178.62.235.215/object.json](http://178.62.235.215/object.json)
- [http://178.62.235.215/array.json](http://178.62.235.215/array.json)

---

<div class="post-metadata">

### Author: ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)
#### Post date: [July 8, 2015, 11:27pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721/4 "2015-07-08T23:27:49Z")

</div>

Hm, I’m not sure if having an array as root is actually valid JSON, but it seems like it parsed correctly as it didn’t complain and you got an AsyncArray in both cases.

I can’t give you a good answer straigt away but we’ll take action to have this looked at.

Thanks for reporting!

---

<div class="post-metadata">

### Author: ![Michael\_Mroz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/michael_mroz/32/466_2.png) [@Michael\_Mroz](https://forums.fusetools.com/u/Michael_Mroz)
#### Post date: [August 17, 2015, 12:39pm UTC](https://forums.fusetools.com/t/fetchjson-from-fusejs-doesnt-accept-array-as-root-element/2721/5 "2015-08-17T12:39:53Z")

</div>

Putting in my two cents: I had the same issue, and also found that it was resolved if I accessed an endpoint that returned an object. Unfortunately, while the API I’d like to access is my own, it’s live and has other developers relying upon it.

To answer the question of whether or not arrays are valid JSON roots, the [short answer is yes](http://json.org/). String, numerical, boolean and null values are too. As to whether or not exercising that freedom is a good idea is [up for debate](http://stackoverflow.com/a/19623421/1880763), but it’s my view that if you’re returning a set, using HTTP errors properly, and have no intention in the current major version of ever adding aggregate statistics, there’s no need to wrap it in an object.

Anyway, I’m just getting started with Fuse (it’s super neat, by the way) and I doubt that `FetchJson` is ideal for what I’m looking at doing just now, so it’s not too big a deal for me, but it seems a really nifty tool to have, and it would be nice if it would work with array roots 🙂
