# Importing JSON code

**URL:** <https://discourse.gohugo.io/t/importing-json-code/4126>\
**Category:** support\
**Created:** [September 20, 2016, 3:57am UTC](https://discourse.gohugo.io/t/importing-json-code/4126 "2016-09-20T03:57:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [September 20, 2016, 3:57am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/1 "2016-09-20T03:57:30Z")

</div>

So I am fairly new but I have been reading for days and can not figure this out. I am not sure if I should use shortcodes or Data-driven Content. Anyway I am editing a page inside the content folder which has an extension of .md. I would like to load the data from my .json file to the page. I need to be able to select certain items from the file as well if possible. Below is a section of the json export from mysql and I would appreciate any help anyone can give me or point in the correct direction. I have read the website but find it difficult to understand or follow.

[{“id”: 1,“type”: “domainaddons”,“currency”: 1,“relid”: 0,“msetupfee”: “0.00”,“qsetupfee”: “0.00”,“ssetupfee”: “2.50”,“asetupfee”: “0.00”,“bsetupfee”: “0.00”,“tsetupfee”: “0.00”,“monthly”: “0.00”,“quarterly”: “0.00”,“semiannually”: “0.00”,“annually”: “0.00”,“biennially”: “0.00”,“triennially”: “0.00”},  
{“id”: 2,“type”: “domainregister”,“currency”: 1,“relid”: 1,“msetupfee”: “9.95”,“qsetupfee”: “19.95”,“ssetupfee”: “32.95”,“asetupfee”: “45.95”,“bsetupfee”: “59.95”,“tsetupfee”: “0.00”,“monthly”: “69.95”,“quarterly”: “79.95”,“semiannually”: “89.95”,“annually”: “99.95”,“biennially”: “-1.00”,“triennially”: “0.00”},  
{“id”: 3,“type”: “domaintransfer”,“currency”: 1,“relid”: 1,“msetupfee”: “9.95”,“qsetupfee”: “-1.00”,“ssetupfee”: “-1.00”,“asetupfee”: “-1.00”,“bsetupfee”: “-1.00”,“tsetupfee”: “0.00”,“monthly”: “-1.00”,“quarterly”: “-1.00”,“semiannually”: “-1.00”,“annually”: “-1.00”,“biennially”: “-1.00”,“triennially”: “0.00”},  
{“id”: 4,“type”: “domainrenew”,“currency”: 1,“relid”: 1,“msetupfee”: “9.95”,“qsetupfee”: “19.95”,“ssetupfee”: “32.95”,“asetupfee”: “45.95”,“bsetupfee”: “59.95”,“tsetupfee”: “0.00”,“monthly”: “69.95”,“quarterly”: “79.95”,“semiannually”: “89.95”,“annually”: “99.95”,“biennially”: “-1.00”,“triennially”: “0.00”},  
{“id”: 5,“type”: “domainregister”,“currency”: 1,“relid”: 2,“msetupfee”: “12.95”,“qsetupfee”: “24.95”,“ssetupfee”: “34.95”,“asetupfee”: “49.95”,“bsetupfee”: “64.95”,“tsetupfee”: “0.00”,“monthly”: “-1.00”,“quarterly”: “-1.00”,“semiannually”: “-1.00”,“annually”: “-1.00”,“biennially”: “-1.00”,“triennially”: “0.00”},  
{“id”: 6,“type”: “domaintransfer”,“currency”: 1,“relid”: 2,“msetupfee”: “12.95”,“qsetupfee”: “-1.00”,“ssetupfee”: “-1.00”,“asetupfee”: “-1.00”,“bsetupfee”: “-1.00”,“tsetupfee”: “0.00”,“monthly”: “-1.00”,“quarterly”: “-1.00”,“semiannually”: “-1.00”,“annually”: “-1.00”,“biennially”: “-1.00”,“triennially”: “0.00”}]

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [September 20, 2016, 5:44am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/2 "2016-09-20T05:44:33Z")

</div>

@Haaser Can you give me an idea of your desired output (in HTML), please?

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [September 20, 2016, 5:58am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/3 "2016-09-20T05:58:45Z")

</div>

Well I need to pull data from a few different json files but I assume that should not be difficult once I get one figured out. We use a business system called WHMCS, and when prices/information changes in the database I will need to export the json file to update the website. So I am not sure if I will have to use hugo to rebuild the site every time or if it can load the information direct from the json file.

Basically my html output is just a table 4 columns with information from server specs, price, location, etc. The best example I can give you is a direct link to the website. [https://www.regencyhost.com/budget-dedicated-servers.php](https://www.regencyhost.com/budget-dedicated-servers.php) as you will see it loads slow which is why I am switching to this but i need to be able to pull information from the json file to populate the site with the correct information.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 20, 2016, 9:02am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/4 "2016-09-20T09:02:40Z")

</div>

> [@Haaser](#):
>
> So I am not sure if I will have to use hugo to rebuild the site every time or if it can load the information direct from the json file.

You would either have to build it every time it changes or load the JSON client side (Javascript, which is a question outside of Hugo).

If you want to load JSON in a content file, I would create a shortcode for it. There isn’t very powerful ways of doing queries in JSON, so I would suggest you do the partitioning of the data when you export it from the database, so you can address the entities you want directly in the object graph, aka. `.Data.hosting.denver` would list the server options in Denver.

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [September 20, 2016, 3:31pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/5 "2016-09-20T15:31:09Z")

</div>

I have never coded shortcode before so I am not sure what I will have to do to the JSON. Each line has a ID field which represents the dedicated server. Is there any documentation on shortcode or how do I go about starting to learn / code this?

Content on the site changes but not that often and I can just rebuild it and upload when it does. I am going for a very fast website so I assume that using javascript to load the json would slow it down?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 20, 2016, 6:13pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/6 "2016-09-20T18:13:51Z")

</div>

> [@Haaser](#):
>
> Is there any documentation on shortcode

Docs: [Getting started | Hugo](http://gohugo.io/overview/introduction/)

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [September 20, 2016, 6:23pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/7 "2016-09-20T18:23:48Z")

</div>

Yes been there lots and it may be friendly to experienced users but for beginners it does not help. I assume this would of helped me more [http://gohugo.io/extras/shortcodes/](http://gohugo.io/extras/shortcodes/) but it does not.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 20, 2016, 6:44pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/8 "2016-09-20T18:44:33Z")

</div>

I wrote the shortcode documentation, so if that doesn’t work, I’m not in a position to make it more clear.

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [September 20, 2016, 10:46pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/9 "2016-09-20T22:46:24Z")

</div>

I think my problem is that I understand what a shortcode can do but I am not sure how to code the shortcode. Is it written in php,java,html or what language? The document tells you how to use shortcodes but does not tell you how to write them. I am just not sure where to begin to code my own shortcode. Also are we sure I should be using shortcodes and not data driven content?

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [September 21, 2016, 3:09am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/10 "2016-09-21T03:09:35Z")

</div>

> [@bep](#):
>
> Docs: [Getting started | Hugo](http://gohugo.io/overview/introduction/)

I think you were pointed to the introduction for good reason here.

I would recommend starting with the overview under templates:

[http://gohugo.io/templates/overview/](http://gohugo.io/templates/overview/)

> [@Haaser](#):
>
> Is it written in php,java,html or what language?

The _only_ thing that Hugo concerns itself with is HTML, which is handled via HTML itself, Golang templates, and your markdown files (which are technically handled by BlackFriday, a markdown renderer written in Golang). If you learn the templating, you’ve learned how to write shortcodes, but asking about Java and PHP indicates to me that you should first RTD.

Cheers.

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [October 11, 2016, 5:55am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/12 "2016-10-11T05:55:46Z")

</div>

So I have been plugging along and learning as I go but I have ran into a problem and I can not figure out what to do to resolve this issue. I am using phpmyadmin to extract our products from mysql to json which it does well but the problem I am having is when hugo builds the site it is changing the \< p \> html tag from json to ascii code. & l t ; p & g t ; but without the spaces as I am not sure how to post it.

Example: [https://www.regencyhost.com/Chad/hosting/budget-dedicated-servers/#zlin](https://www.regencyhost.com/Chad/hosting/budget-dedicated-servers/#zlin)

{“id”: 126,“name”: “Bargain Server 1”,“description”: “

Dual Core ATOM ( 2 x 1.6Ghz )  
2GB RAM, 250GB HDD 10Mbps, 100Mbps, 1Gbps

”},

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [October 11, 2016, 7:41pm UTC](https://discourse.gohugo.io/t/importing-json-code/4126/13 "2016-10-11T19:41:41Z")

</div>

See the `safeHTML` template function.

---

<div class="post-metadata">

**Author:** ![Haaser](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Haaser](https://discourse.gohugo.io/u/Haaser)\
**Post date:** [October 12, 2016, 2:42am UTC](https://discourse.gohugo.io/t/importing-json-code/4126/14 "2016-10-12T02:42:55Z")

</div>

Thank you that worked!
