# JSON format error

**URL:** https://forums.fusetools.com/t/json-format-error/5326
**Category:** General
**Created:** [July 12, 2016, 12:44pm UTC](https://forums.fusetools.com/t/json-format-error/5326 "2016-07-12T12:44:08Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 12:44pm UTC](https://forums.fusetools.com/t/json-format-error/5326/1 "2016-07-12T12:44:08Z")

</div>

I am trying to fetch JSON data, but I cannot seem to get it processed to the right format. The JSON I want to fetch looks like this: `{"someName":{"id":55514376,"name":"SomeName2","profileIconId":533}}`

Is there any way to display the someName and then the attributes it has?

If I am using this code: `<Text Value="{someName}" TextWrapping="Wrap" Alignment="Left" Margin="5" />` it does not work. If I edit the JSON to be only the attributes, like this: `[{"id":55514376,"name":"SomeName2","profileIconId":533}]` , it works fine.

---

<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 12, 2016, 1:03pm UTC](https://forums.fusetools.com/t/json-format-error/5326/2 "2016-07-12T13:03:20Z")

</div>

Hi,

In your first dataset, it looks like what you want is `<Text Value="{someName.name}" />`. Does that help?

---

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 1:11pm UTC](https://forums.fusetools.com/t/json-format-error/5326/3 "2016-07-12T13:11:23Z")

</div>

> **Anders Lassen wrote:**
> 
> Hi,
> 
> In your first dataset, it looks like what you want is `<Text Value="{someName.name}" />`. Does that help?

Kind of! :). I had to add in the beginning and in the end of the JSON for it to work. Is there a way so the brackets are not needed? Since the JSON I get from the api doesn’t include the brackets.

Maybe I can just add the brackets to the observable I created, or?

---

<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 12, 2016, 1:15pm UTC](https://forums.fusetools.com/t/json-format-error/5326/4 "2016-07-12T13:15:41Z")

</div>

If you are using your data in an `Each`, then yes, it must be an array. Otherwise you shouldn’t need to.

---

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 1:29pm UTC](https://forums.fusetools.com/t/json-format-error/5326/5 "2016-07-12T13:29:37Z")

</div>

Makes sense :).

If I have a lot of different unknown “someName” is there a way to get all of those and their attributes?

I’m using this json for the testing: `[https://api.myjson.com/bins/4echf](https://api.myjson.com/bins/4echf)` (I’ve changed someName to frederik)

---

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 1:44pm UTC](https://forums.fusetools.com/t/json-format-error/5326/6 "2016-07-12T13:44:31Z")

</div>

> **FrederikBruun wrote:**
> 
> Makes sense :).
> 
> If I have a lot of different unknown “someName” is there a way to get all of those and their attributes?
> 
> I’m using this json for the testing: `[https://api.myjson.com/bins/4echf](https://api.myjson.com/bins/4echf)` (I’ve changed someName to frederik)

Or rather JSON of this format:

`{"champions":[{"id":266,"active":true,"botEnabled":false,"freeToPlay":false,"botMmEnabled":false,"rankedPlayEnabled":true},{"id":103,"active":true,"botEnabled":false,"freeToPlay":false,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":84,"active":true,"botEnabled":false,"freeToPlay":false,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":12,"active":true,"botEnabled":true,"freeToPlay":false,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":32,"active":true,"botEnabled":true,"freeToPlay":false,"botMmEnabled":true,"rankedPlayEnabled":true}]}`

---

<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 12, 2016, 1:50pm UTC](https://forums.fusetools.com/t/json-format-error/5326/7 "2016-07-12T13:50:52Z")

</div>

> If I have a lot of different unknown “someName” is there a way to get all of those and their attributes?

I didn’t understand the question, sorry

---

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 2:02pm UTC](https://forums.fusetools.com/t/json-format-error/5326/8 "2016-07-12T14:02:00Z")

</div>

Let’s say I want to list all of the different id’s in the JSON above. How could I do that? 🙂

---

<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 12, 2016, 2:37pm UTC](https://forums.fusetools.com/t/json-format-error/5326/9 "2016-07-12T14:37:50Z")

</div>

List them how? In the app UI?

---

<div class="post-metadata">

### Author: ![petterroea](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/petterroea/32/438_2.png) [@petterroea](https://forums.fusetools.com/u/petterroea)
#### Post date: [July 12, 2016, 2:38pm UTC](https://forums.fusetools.com/t/json-format-error/5326/10 "2016-07-12T14:38:47Z")

</div>

I am assuming you are fetching this data from a web-api. The biggest challenge when doing that, is that you need to convert the data to an observable, and make your `someName`'s reachable from ux by converting them to values instead of a key.

Have a look at this for some information on how that is done: [http://stackoverflow.com/questions/983267/access-the-first-property-of-an-object](http://stackoverflow.com/questions/983267/access-the-first-property-of-an-object)

Here is an example that downloads your json file, and converts it to something we can show in UX:

```auto
  <JavaScript>
    var Observable = require("FuseJS/Observable");
    var userData = Observable();
    fetch('https://api.myjson.com/bins/4echf').then(function(response) {
        return response.json();
    }).then(function(value) {
        userData.replaceAll(value); //Fill an observable with the data
    });
    module.exports = {
        users: userData.map(function(item) {
        return {name: Object.keys(item)[0],
            data: item[Object.keys(item)[0]]};
    })
    };
  </JavaScript>
  <StackPanel>
    <Each Items="{users}">
      <StackPanel Orientation="Horizontal">
    <Text Value="{name}" />
    <Text Value="{data.id}" TextColor="#aaa" FontSize="10" Alignment="Center" Margin="10,0,0,0"/>
      </StackPanel>
    </Each>
  </StackPanel>

```

This is what we are doing:

- `fetch`ing your json file, and parsing the json from it
- Feed the parsed json into an observable we call `userData`(we use `replaceAll` since the json’s root container is an array, so we expect multiple users)
- Map every entry in the `userData` array to another observable, where we map the key, `somename`, to the value of a key called `name`, and the value of `someName` to `data`.

The converted array should look something like this:

```auto
[{"name": "frederik", "data": {"id":55238276,"name":"Frederik","profileIconId":531,"summonerLevel":30,"revisionDate":1467543446000}}]

```

Note that you can avoid all this by having `someName` as a value, not a key, in your json data.

Have fun 🙂

---

<div class="post-metadata">

### Author: ![Frederik\_Bruun](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Frederik\_Bruun](https://forums.fusetools.com/u/Frederik_Bruun)
#### Post date: [July 12, 2016, 2:52pm UTC](https://forums.fusetools.com/t/json-format-error/5326/11 "2016-07-12T14:52:00Z")

</div>

Thanks a lot to both of you! 🙂

I’ll take a look at this later when I have the time.
