{"id":4006,"date":"2022-02-14T10:14:59","date_gmt":"2022-02-14T18:14:59","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=4006"},"modified":"2022-02-14T10:15:02","modified_gmt":"2022-02-14T18:15:02","slug":"how-to-import-data-from-json-files-and-rest-apis-into-power-bi","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=4006","title":{"rendered":"How to Import Data from JSON Files and Rest APIs into Power BI"},"content":{"rendered":"\n<p>by&nbsp;Ben Richardson<\/p>\n\n\n\n<p>In this article, you will see how to import data from JSON files and Power BI Rest API into the Power BI environment.<\/p>\n\n\n\n<p>Power BI is a Microsoft application for data analytics and visualization. With Power BI, you can create interactive data visualizations without writing a single line of code. To create a visualization in Power BI, you need a data source that can be in the form of a flat-file such as CSV, TSV, or a database like MS SQL Server. Data can also be retrieved from online sources via Power BI Rest API calls.<\/p>\n\n\n\n<p>In the first section of the article, we will analyze data imported via a local JSON file. In the second section, we will import data from a remote location via REST API calls and explore it with the help of Power BI visualizations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"importing-data-from-json-files\">Importing data from JSON files<\/h2>\n\n\n\n<p>JSON stands for JavaScript Object Notation and is one of the most commonly used formats for data exchange between different platforms and applications. With Power BI, you can export data from JSON files to create different types of visualization.<\/p>\n\n\n\n<p>To import JSON files, go to the Power BI dashboard and click the \u201cGet Data\u201d tab from the top menu. From the list of data sources, select \u201cJSON\u201d as shown in the following screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/connecting-to-a-json-data-source.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/connecting-to-a-json-data-source.png\" alt=\"Connecting to a JSON data source\n\"\/><\/a><\/figure>\n\n\n\n<p>Locate the JSON file that contains your dataset and import it into the Power BI desktop. The JSON file that we are going to import contains 100 fictional records of different persons. The first five records in our JSON file look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"268\" height=\"468\" src=\"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2022\/02\/image.png\" alt=\"\" class=\"wp-image-4007\" srcset=\"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2022\/02\/image.png 268w, https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2022\/02\/image-172x300.png 172w\" sizes=\"(max-width: 268px) 100vw, 268px\" \/><\/figure>\n\n\n\n<p>You can see that each person has four properties, i.e., \u201cPerson_Id\u201d, \u201cPerson_Name\u201d, \u201cPerson_Age\u201d, and \u201cPerson_Gender\u201d. With Power BI, these properties will be converted into columns.<\/p>\n\n\n\n<p>Once the above JSON file is imported, you should see a list with 100 records, as shown in the following screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-once-data-in-the-json-file-has-been-imp.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-once-data-in-the-json-file-has-been-imp.png\" alt=\"Screenshot once data in the JSON file has been imported. \n\"\/><\/a><\/figure>\n\n\n\n<p>If you click on any record, you will see the details of one person, as shown below. You can see the values for the \u201cPerson_Id\u201d, \u201cPerson_Name\u201d, \u201cPerson_Age\u201d, and \u201cPerson_Gender\u201d columns.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-the-data-imported-for-each-reco.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-the-data-imported-for-each-reco.png\" alt=\"Screenshot showing the data imported for each record. \"\/><\/a><\/figure>\n\n\n\n<p>To revert to the previous window, click the \u201cX Navigation\u201d button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-how-to-navigate-to-previous-scr.png\" alt=\"Screenshot showing how to navigate to previous screen by clicking 'X'\"\/><\/figure>\n\n\n\n<p>To convert the List into the table, click the \u201cTo Table\u201d button from the top menu, as shown in the following screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-where-the-to-table-button-is.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-where-the-to-table-button-is.png\" alt=\"Screenshot showing where the 'To Table' button is to create a table. \"\/><\/a><\/figure>\n\n\n\n<p>Your list will be converted into a table with 1 column. The column contains one record per person, and each record contains 4 values.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-how-the-data-will-look-when-converted-int.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-how-the-data-will-look-when-converted-int.png\" alt=\"Image of how the data will look when converted into a one column table. \"\/><\/a><\/figure>\n\n\n\n<p>To create 4 columns, click on the \u201c\u201d button at the top right corner of the column name as shown in the following figure and click the \u201cOK\u201d button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-showing-how-to-convert-the-one-column-table.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-showing-how-to-convert-the-one-column-table.png\" alt=\"Image showing how to convert the one column table into a four column table. \"\/><\/a><\/figure>\n\n\n\n<p>You JSON will be converted into a table, as shown below. You can see the four column names that correspond to the properties in JSON files.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-the-data-in-a-four-column-format-after-co.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-the-data-in-a-four-column-format-after-co.png\" alt=\"Image of the data in a four column format after conversion. \"\/><\/a><\/figure>\n\n\n\n<p>To create a visualization in the form of a report, you will need to save this table.<\/p>\n\n\n\n<p>To do so, click the \u201cClose &amp; Apply\u201d button, as shown below. Once you have done that, you will be taken to the Reports View.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-showing-where-the-close-and-apply-button-is-.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-showing-where-the-close-and-apply-button-is-.png\" alt=\"Image showing where the 'Close &amp; Apply' button is. \"\/><\/a><\/figure>\n\n\n\n<p>From the reports view, select the \u201cClustered column chart\u201d, as shown in the \u201cVisualization\u201d field below. Add the \u201cPerson Gender\u201d column to the Axis and \u201cPerson Age\u201d column to the Value field.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/setting-up-the-data-visualisation-in-the-reports-v.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/setting-up-the-data-visualisation-in-the-reports-v.png\" alt=\"Setting up the data visualisation in the reports view. \"\/><\/a><\/figure>\n\n\n\n<p>A clustered column chart, such as the one shown below, will be created. The chart shows that the number of persons with gender id 0 is higher than the ones with gender id 1.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/a-simple-graph-showing-distribution-of-men-and-wom.png\" alt=\"A simple graph showing distribution of men and women in the data. \"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"importing-with-power-bi-rest-api-calls\">Importing with Power BI Rest API Calls<\/h2>\n\n\n\n<p>With Power BI Rest API calls, you can import data from websites that provide restful APIs for data access. Once the data is imported, you can treat it like any other data file such as JSON or CSV, etc.<\/p>\n\n\n\n<p>In this article, we will be importing information about the 8 different houses from the TV Show Game of Thrones. The data is hosted here,&nbsp;<a href=\"https:\/\/anapioficeandfire.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/anapioficeandfire.com\/<\/a>. The website provides an API to access books, characters, and houses from the novel series: A Song Of Ice And Fire.<\/p>\n\n\n\n<p>If you click this link, the below will appear in your browser window.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-data-available-when-clicking-th.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/screenshot-showing-data-available-when-clicking-th.png\" alt=\"Screenshot showing data available when clicking the link to the power bi rest api at  anapioficeandfire.com\"\/><\/a><\/figure>\n\n\n\n<p>To get data via Power BI Rest API calls, you have to specify \u201cWeb\u201d as the data source in the \u201cGet Data\u201d menu, as shown below. Click the \u201cConnect\u201d button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-the-correct-settings-to-download-data-fro.png\" alt=\"Image of the correct settings to download data from the website of the power bi rest api\"\/><\/figure>\n\n\n\n<p>In the dialogue box that appears, specify&nbsp;<a href=\"https:\/\/anapioficeandfire.com\/api\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/anapioficeandfire.com\/api\/<\/a>&nbsp;in the first part and \u201chouses\/\u201d in the second part. The final URL will be&nbsp;<a href=\"https:\/\/anapioficeandfire.com\/api\/houses\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/anapioficeandfire.com\/api\/houses\/<\/a>. Click the OK button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-showing-the-final-setting-required-to-down-l.png\" alt=\"Image showing the final setting required to down load the dataset using the power bi rest api\"\/><\/figure>\n\n\n\n<p>The dataset will be loaded in Power BI Query editor in the form of a JSON file having 10 records.<\/p>\n\n\n\n<p>Each record contains information about one of the houses in the novel series, as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/the-data-as-it-appears-when-first-uploaded-.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/the-data-as-it-appears-when-first-uploaded-.png\" alt=\"The data as it appears when first uploaded. \"\/><\/a><\/figure>\n\n\n\n<p>The rest of the process is similar to what you did in order to expand data imported via JSON files above.<\/p>\n\n\n\n<p>Click on the \u201cTo Table\u201d option from the menu bar. The dataset will be converted to a table.<\/p>\n\n\n\n<p>Again, extend the column by clicking the \u201c&lt;-&gt;\u201d symbol at the top of the column name as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/clicking-the-less-greater-symbol-to-extend-the-column-of-da.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/clicking-the-less-greater-symbol-to-extend-the-column-of-da.png\" alt=\"Clicking the <-&gt; symbol to extend the column of data\"\/><\/a><\/figure>\n\n\n\n<p>You will see all the column names, as shown below. Click the OK button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/the-screen-when-all-column-names-are-visible-.png\" alt=\"The screen when all column names are visible. \"\/><\/figure>\n\n\n\n<p>The column names will be extended. If you look at the \u201ctitles\u201d and \u201cseats\u201d columns, you will see that the columns are lists. Expand the columns in the same way that you expanded the original list column by clicking the \u201c&lt;-&gt;\u201d button at the top right of the column name as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/expanding-the-columns-again-using-less-greater.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/expanding-the-columns-again-using-less-greater.png\" alt=\"Expanding the columns again using <-&gt; \"\/><\/a><\/figure>\n\n\n\n<p>Once you expand both the \u201ctitle\u201d and the \u201cseats\u201d column, the dataset should look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/the-dataset-once-the-title-and-seats-columns-h.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/the-dataset-once-the-title-and-seats-columns-h.png\" alt=\"The dataset once the 'title' and 'seats' columns have been expanded. \"\/><\/a><\/figure>\n\n\n\n<p>You can see that duplicate records have been added when you expand the \u201ctitle\u201d and \u201cseats\u201d column. This is because one house can have multiple titles and seats. Therefore, for each title and seat, a new row is added, resulting in duplicate rows for house names.<\/p>\n\n\n\n<p>Click on the \u201cClose &amp; Apply\u201d button from the top menu to open this dataset in the Query window.<\/p>\n\n\n\n<p>The final step is to create a simple visualization using this data. We will create a simple pie chart that will show the distribution of ancestral weapons by region.<\/p>\n\n\n\n<p>To do this, start by clicking on the \u201cpie\u201d chart option from visualizations, as shown below. In the \u201cLegend\u201d field, add \u201cregion\u201d and in the values, field add \u201cCount of ancestral Weapons\u201d, as shown in the following screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/setting-up-the-simple-pie-chart-.png\" alt=\"Setting up the simple pie chart.\"\/><\/figure>\n\n\n\n<p>The following Pie chart will be created as a result. The pie chart shows that almost 50% of the ancestral weapons belong to the region \u201cThe Vale\u201d. Similarly, 11.1% of weapons belong to each of the \u201cThe Reach\u201d and \u201cThe North\u201d region.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-the-final-pie-chart-.png\"><img decoding=\"async\" src=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/08\/image-of-the-final-pie-chart-.png\" alt=\"Image of the final pie chart.\"\/><\/a><\/figure>\n\n\n\n<p>In the same way, you can try and add other visualizations to further explore the data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>Power BI can import data from a variety of data sources such as CSV, TSV, JSON files, online flat files, databases, and via power BI REST API calls. In this article, we looked at how to import data via the JSON files and how to use Power BI Rest API calls to import data from websites that provide support for REST APIs. With JSON files, data is imported in the form of records, which you have to first convert to a table. Then you have to expand the table containing JSON records to create one column for each property in a record. With power BI REST APIs, you can import data from a remote location in the form of a JSON file and then explore the data just as you would a local JSON file.<\/p>\n\n\n\n<p>Ref: <\/p>\n","protected":false},"excerpt":{"rendered":"<p>by&nbsp;Ben Richardson In this article, you will see how to import data from JSON files and Power BI Rest API into the Power BI environment. Power BI is a Microsoft application for data analytics and visualization. With Power BI, you can create interactive data visualizations without writing a single line of code. To create a <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=4006\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,621],"tags":[1110,1111],"class_list":["post-4006","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-power-bi","tag-import-data-from-json","tag-import-data-from-rest-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4006"}],"version-history":[{"count":2,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4006\/revisions"}],"predecessor-version":[{"id":4013,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4006\/revisions\/4013"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}