# Help me: How to read a native Json file in Ionic 2

**URL:** <https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796>\
**Category:** ionic-v3\
**Created:** [May 3, 2017, 5:26pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796 "2017-05-03T17:26:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 3, 2017, 5:26pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/1 "2017-05-03T17:26:31Z")

</div>

Hello all, I am developing a bible application in ionic 2, I have everything ready, the pages and everything, my problem is that I do not know how to call or read a Json file within the project. This is an example of the file

```auto
[{"abbrev": "gn", "book": "Genesis", "chapters": [{"1": {"1": "At the first God made the heaven and the earth.", "2": "And the earth was waste and without form; and it was dark on the face of the deep: and the Spirit of God was moving on the face of the waters.", "3": "And God said, Let there be light: and there was light.", "4": "And God, looking on the light, saw that it was good: and God made a division between the light and the dark,", "5": "Naming the light, Day, and the dark, Night. And there was evening and there was morning, the first day.", "6": "And God said, Let there be a solid arch stretching over the waters, parting the waters from the waters.", "7": "And God made the arch for a division between the waters which were under the arch and those which were over it: and it was so.""}}]}]

```

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [May 3, 2017, 7:27pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/2 "2017-05-03T19:27:29Z")

</div>

Where does this file live?

---

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 3, 2017, 7:28pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/3 "2017-05-03T19:28:38Z")

</div>

Hello, I have it inside the www folder, example www / Gif / gif.json

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [May 3, 2017, 7:30pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/4 "2017-05-03T19:30:21Z")

</div>

> **[How to Manipulate Data in Ionic 2: Part 1](https://www.joshmorony.com/how-to-manipulate-data-in-ionic-2-part-1/)**
>
> Most applications rely heavily on data, so it’s important that we know how best to manipulate that data in order to make it do what we want. Sometimes this data is stored on some remote serve…

---

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 3, 2017, 7:31pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/5 "2017-05-03T19:31:04Z")

</div>

I have the call of the following form, forgive the disorder, esque everything I have done with tutorials, I just want to learn.

```auto
export class HelloIonicPage 
{

    posts: any;
  constructor(public navCtrl: NavController, public http: Http) 
  {        
         this.http.get('gif/gif.json').map(res => res.json()).subscribe(data => {
            this.posts = data.data.children;
        },
        err => 
        {
        console.log("Oops!");
        
        }
    );
  }
}

```

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [May 3, 2017, 7:38pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/6 "2017-05-03T19:38:25Z")

</div>

And what is happening?  
Add a console.log(data) inside the subscribe to have a look at the data.

The JSON you posted in your first post is actually invalid! If you copy/paste it on [jsonlint.com](http://jsonlint.com) you get an error. There is an `"` too much. This is the fixed version:

```auto
[{
	"abbrev": "gn",
	"book": "Genesis",
	"chapters": [{
		"1": {
			"1": "At the first God made the heaven and the earth.",
			"2": "And the earth was waste and without form; and it was dark on the face of the deep: and the Spirit of God was moving on the face of the waters.",
			"3": "And God said, Let there be light: and there was light.",
			"4": "And God, looking on the light, saw that it was good: and God made a division between the light and the dark,",
			"5": "Naming the light, Day, and the dark, Night. And there was evening and there was morning, the first day.",
			"6": "And God said, Let there be a solid arch stretching over the waters, parting the waters from the waters.",
			"7": "And God made the arch for a division between the waters which were under the arch and those which were over it: and it was so."
		}
	}]
}]

```

---

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 3, 2017, 7:55pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/7 "2017-05-03T19:55:23Z")

</div>

Okay, I’ve already modified it, I stay as you said. Now, what do I do to call it? If you could give me an example of the book of genesis, you would infinitely please it.  
I want it on the hell ionic page:  
Genesis  
[1.In](http://1.In) the beginning God created the heavens and the earth … etc.

---

<div class="post-metadata">

**Author:** ![luukschoen](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/luukschoen/32/98585_2.png) [@luukschoen](https://forum.ionicframework.com/u/luukschoen)\
**Post date:** [May 3, 2017, 7:57pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/8 "2017-05-03T19:57:29Z")

</div>

You should move it under the assets folder I guess. Move it to assets/data or assets/json or whatever you want… then call it with `this.http.get('assets/data/my_file.json')` and it should work fine.

---

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 3, 2017, 8:22pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/9 "2017-05-03T20:22:53Z")

</div>

A little doubt, how should the html file be?

```auto
<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>BIBLIA RV</ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
    
</ion-content>

```

---

<div class="post-metadata">

**Author:** ![luukschoen](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/luukschoen/32/98585_2.png) [@luukschoen](https://forum.ionicframework.com/u/luukschoen)\
**Post date:** [May 4, 2017, 6:51am UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/10 "2017-05-04T06:51:31Z")

</div>

Looks fine to me. If I were you, I would abstract the http call into a service (let’s call it myService) which returns something like this to your HelloIonicPage:

`getBooks(): Observable<any> { return this.http.get('gif/gif.json').map(res => res.json()); }`

Where any should/could be replaced by the actual response type (if it’s known).

now you can call something like this from your page:

```auto
  this.myService.getBooks.subscribe(
    (result) => {
      this.posts = result;
    },
    (err) => {
      console.warn('Oops, something went wrong')
    },
    () => {
      console.log('done running this function')
    }
   )

```

---

<div class="post-metadata">

**Author:** ![jhan321](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jhan321/32/109229_2.png) [@jhan321](https://forum.ionicframework.com/u/jhan321)\
**Post date:** [May 4, 2017, 1:21pm UTC](https://forum.ionicframework.com/t/help-me-how-to-read-a-native-json-file-in-ionic-2/88796/11 "2017-05-04T13:21:34Z")

</div>

Muchas gracias, es usted muy amable con sus respuestas, me sirvio mucho.  
Thank you very much, you are very kind with your answers, I served a lot.
