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


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:

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

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

Snip of the .UX code:

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

Example data:

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? :slight_smile:


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.


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 :confused:

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

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!

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. String, numerical, boolean and null values are too. As to whether or not exercising that freedom is a good idea is up for debate, 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 :slight_smile: