I solved it by making this

var vue = new Vue({
  el:'#textExample',
  data:{
    loans:[ { "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "10": 10, "11": 11, "12": 12 }, { "1": 70000, "2": 66524.45, "3": 62736.11, "4": 58606.81, "5": 54105.88, "6": 49199.86, "7": 43852.3, "8": 38023.47, "9": 31670.03, "10": 24744.79, "11": 17196.27, "12": 8968.39 }, { "1": 3475.55, "2": 3788.35, "3": 4129.3, "4": 4500.93, "5": 4906.02, "6": 5347.56, "7": 5828.84, "8": 6353.43, "9": 6925.24, "10": 7548.52, "11": 8227.88, "12": 8968.39 }, { "1": 6300, "2": 5987.2, "3": 5646.25, "4": 5274.61, "5": 4869.53, "6": 4427.99, "7": 3946.71, "8": 3422.11, "9": 2850.3, "10": 2227.03, "11": 1547.66, "12": 807.16 }, { "1": 9775.55, "2": 9775.55, "3": 9775.55, "4": 9775.55, "5": 9775.55, "6": 9775.55, "7": 9775.55, "8": 9775.55, "9": 9775.55, "10": 9775.55, "11": 9775.55, "12": 9775.55 }, { "1": "Mar 17, 2018", "2": "Apr 16, 2018", "3": "May 16, 2018", "4": "Jun 15, 2018", "5": "Jul 15, 2018", "6": "Aug 14, 2018", "7": "Sep 13, 2018", "8": "Oct 13, 2018", "9": "Nov 12, 2018", "10": "Dec 12, 2018", "11": "Jan 11, 2019", "12": "Feb 10, 2019" }, { "1": 66524.45, "2": 62736.11, "3": 58606.81, "4": 54105.88, "5": 49199.86, "6": 43852.3, "7": 38023.47, "8": 31670.03, "9": 24744.79, "10": 17196.27, "11": 8968.39, "12": 0 } ]
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script>
<div id="textExample">
  <table class="table table-bordered">
			<thead>
				<tr>
					<th> Month</th>
					<th> Opening Principal</th>
					<th> Principal Taken</th>
					<th> Interest</th>
					<th> Payment</th>
					<th> Repayment Date</th>
					<th> Closing Principal</th>
				</tr>
			</thead>
			<tr v-for="loan in loans[0]">
				<td v-for="otherloan in loans">{{otherloan[loan]}}</td>

			</tr>


		</table>
</div>

by only changing the tr and td tags v-for's like this:

<tr v-for="loan in loans[0]">
                <td v-for="otherloan in loans">{{otherloan[loan]}}</td>

            </tr>
Answer from Ahmed Ali Thabet on Stack Overflow
Top answer
1 of 2
5

I solved it by making this

var vue = new Vue({
  el:'#textExample',
  data:{
    loans:[ { "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "10": 10, "11": 11, "12": 12 }, { "1": 70000, "2": 66524.45, "3": 62736.11, "4": 58606.81, "5": 54105.88, "6": 49199.86, "7": 43852.3, "8": 38023.47, "9": 31670.03, "10": 24744.79, "11": 17196.27, "12": 8968.39 }, { "1": 3475.55, "2": 3788.35, "3": 4129.3, "4": 4500.93, "5": 4906.02, "6": 5347.56, "7": 5828.84, "8": 6353.43, "9": 6925.24, "10": 7548.52, "11": 8227.88, "12": 8968.39 }, { "1": 6300, "2": 5987.2, "3": 5646.25, "4": 5274.61, "5": 4869.53, "6": 4427.99, "7": 3946.71, "8": 3422.11, "9": 2850.3, "10": 2227.03, "11": 1547.66, "12": 807.16 }, { "1": 9775.55, "2": 9775.55, "3": 9775.55, "4": 9775.55, "5": 9775.55, "6": 9775.55, "7": 9775.55, "8": 9775.55, "9": 9775.55, "10": 9775.55, "11": 9775.55, "12": 9775.55 }, { "1": "Mar 17, 2018", "2": "Apr 16, 2018", "3": "May 16, 2018", "4": "Jun 15, 2018", "5": "Jul 15, 2018", "6": "Aug 14, 2018", "7": "Sep 13, 2018", "8": "Oct 13, 2018", "9": "Nov 12, 2018", "10": "Dec 12, 2018", "11": "Jan 11, 2019", "12": "Feb 10, 2019" }, { "1": 66524.45, "2": 62736.11, "3": 58606.81, "4": 54105.88, "5": 49199.86, "6": 43852.3, "7": 38023.47, "8": 31670.03, "9": 24744.79, "10": 17196.27, "11": 8968.39, "12": 0 } ]
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script>
<div id="textExample">
  <table class="table table-bordered">
			<thead>
				<tr>
					<th> Month</th>
					<th> Opening Principal</th>
					<th> Principal Taken</th>
					<th> Interest</th>
					<th> Payment</th>
					<th> Repayment Date</th>
					<th> Closing Principal</th>
				</tr>
			</thead>
			<tr v-for="loan in loans[0]">
				<td v-for="otherloan in loans">{{otherloan[loan]}}</td>

			</tr>


		</table>
</div>

by only changing the tr and td tags v-for's like this:

<tr v-for="loan in loans[0]">
                <td v-for="otherloan in loans">{{otherloan[loan]}}</td>

            </tr>
2 of 2
1

A proper solution would iterate over the loans, creating a table row for each. The inner loop would iterate over the properties of a loan and display a table cell with each one's value.

Discussions

vue.js - how to display json in table vuejs - Stack Overflow
how to display the following json data ? i have json data like this, and want to display it in table, i use vue-bostrapt . Previously I tried like this, but it's not perfect. this my json [ { ... More on stackoverflow.com
🌐 stackoverflow.com
Adding table rows from JSON result with VueJS?
I am fetching some data from the backend and it gives me a JSON result. Console logs work, so it is retrieving the data just fine. I need to get specific data and dynamically add that to a table as More on stackoverflow.com
🌐 stackoverflow.com
May 21, 2020
Loop to create table from JSON data - Vue Forum
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects. More on forum.vuejs.org
🌐 forum.vuejs.org
March 29, 2020
How to display the workHr that comes as json data in table format using vue js?
Can you change your JSON API? That’s a really unhelpful data model for what you’re trying to do. ... I think this is what you are asking for. Iterate over the weekTimings and display each value in your table. More on stackoverflow.com
🌐 stackoverflow.com
November 13, 2017
🌐
GitHub
github.com › ratiw › vue-table
GitHub - ratiw/vue-table: data table simplify! -- vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination component.
vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination sub-component.
Starred by 1.8K users
Forked by 296 users
Languages   Vue 98.5% | Vue 98.5%
🌐
GitHub
github.com › faaezahmd › vue-json-to-html-table
GitHub - faaezahmd/vue-json-to-html-table: Vue 3 Component to display JSON Data as html tables
A Vue.js 3 component to transform json data in to html. ... import VueJsonToHtmlTable from 'vue-json-to-html-table'; import 'vue-json-to-html-table/dist/style.css';
Author   faaezahmd
🌐
npm
npmjs.com › package › vue-json-to-table
vue-json-to-table - npm
March 3, 2020 - A Vue component that renders JSON data in Table structure. ... Open `main.js` and add the following: import VueJsonToTable from 'vue-json-to-table' Vue.use(VueJsonToTable)
      » npm install vue-json-to-table
    
Published   Mar 03, 2020
Version   1.0.7
Author   Shashank Gaurav
🌐
Font Awesome
fontawesomeicons.com › fa › vue-js-json-data-display-in-table
Vue Js Display JSON Data In Table - Font Awesome Icons
Vue Js Display JSON Data In Table - To display JSON data in a table using Vue.js, we can use the v-for directive to iterate over the array of objects and generate table rows for each object. The v-for directive has a special syntax that allows us to create an alias for each object element being ...
Find elsewhere
🌐
Vuetable
vuetable.com › guide
Introduction | Vuetable-2
You begin by defining data fields for your JSON data structure that you want to present in HTML table. Then, progressively configuring it to display the data the way you want. Ultimately, you can use it to create a wrapper component to contain the UI/UX of your own datatable component in one place to achieve consistant look and feel. Work with data from API endpont or existing data array/object
🌐
Stack Overflow
stackoverflow.com › questions › 61924631 › adding-table-rows-from-json-result-with-vuejs
Adding table rows from JSON result with VueJS?
May 21, 2020 - myMethod: function () { var res = this; var table = $('#tableID'); fetch('/Contr/Get', { method: 'POST', headers: { 'Content-Type': 'application/json' }, }) .then(function (response) { return response.json(); }) .then(function (data) { res.id = data.Id; res.type = data.Type; for (var i = 0; i < data.length; i++) { var object = data[i]; $('#tableID').append(`<tr> <td><input v-for='item in data' type="text" :value="{{ item.Id }}" /></td> <td><input v-for='item in data' type="text" style="text-align: right;" maxlength="2" :value="{{ item.Type }}" /></td> </tr >`) } }); } ... This is exactly what Vue's v-for is for.
🌐
JSFiddle
jsfiddle.net › pmiranda › 651fxdwr
Vue.js data table from JSON - JSFiddle - Code Playground
CSS Import: @import url('@jsfiddle/[username]/[fiddle].css') See how this works in this fiddle. The fiddle listings (Public, Private, Titled, etc) will now display latest versions instead of the ones saved as Base versions - this was causing more confusion than good, so we decided to change this long-standing behavior.
🌐
Vue.js Examples
vuejsexamples.com › a-vue-js-component-that-will-automatically-request-json-data
data table simplify with Vue.js - Vue.js Examples
August 17, 2016 - vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination component. vuetable - data table simplify!
🌐
YouTube
youtube.com › code with er.
How To Fetch Local JSON Data Using "V-For" Directive in Vue.Js & Show Data in HTML Table. - YouTube
How To Fetch Local JSON Data Using "V-For" Directive in Vue.Js & Show Data in HTML Table.How To Fetch JSON Data in Vue.jsVue js Easy Tutorial.Vue Totorial.Fe...
Published   September 22, 2023
Views   56
🌐
YouTube
youtube.com › watch
#6 Display json data in vue js and vuex app | VueJS Beginner Tutorial | Vuex Beginner Tutorial - YouTube
Display JSON data in vue js and vuex app | VueJS Beginner Tutorial | Vuex Beginner Tutorial [ 2021]Code used in the video:https://zarx.biz/download/file/eef2...
Published   January 30, 2021
Views   2K
Top answer
1 of 3
6

I think this is what you are asking for. Iterate over the weekTimings and display each value in your table.

    var data = {  
       "status":true,
       "data":{  
          "pid":10,
          "businessName":"Ey technology",
          "services":"1, 3, 4, 2",
          "inventory":[  
             "specs",
             "Eye Testing",
             "Lens",
             "Doctors"
          ],
          "workHr":"Monday :9:00AM to 5:00PM,Thuesday :9:00AM to 5:00PM,Wednesday :9:00AM to 5:00PM,Tuesday : 9:00AM to 5:00PM,Friday :9:00AM to 5:00PM,Saturday :9:00AM to 5:00PM,Sunday :9:00AM to 5:00PM",
          "description":"Good technology company for software",
          "category":1,
          "sub_category":[  
             "Homeo pathy",
             "Web development"
          ],
          "lat":9.5274336,
          "lon":76.8224309,
          "contactName":"simon",
          "contactEmail":"[email protected]",
          "contactOfficeAddress":"college of Eng",
          "contactNumber":"1236547859",
          "contactOfficeNumber":"8947123658",
          "state":"Kerala",
          "city":"Koy",
          "place":"Kly",
          "pincode":686514,
          "referer":24,
          "link":24,
          "views":0,
          "package":1,
          "listing_pic":"default",
          "website":"www.ey.com"
       }
    }

    var weekTimings = data.data.workHr.split(",").map(day => {
        let arr = day.split(":")
        arr.splice(0,1);
        return arr.join(":");
    });

    var sundayTiming = weekTimings.pop();
    weekTimings.unshift(sundayTiming);
    console.log(weekTimings);
   
   // You can do like below using JS or you can use jQuery and shorten your code
   document.getElementById("sun").innerHTML = weekTimings[0];
   document.getElementById("mon").innerHTML = weekTimings[1];
   document.getElementById("tue").innerHTML = weekTimings[2];
   document.getElementById("wed").innerHTML = weekTimings[3];
   document.getElementById("thu").innerHTML = weekTimings[4];
   document.getElementById("fri").innerHTML = weekTimings[5];
   document.getElementById("sat").innerHTML = weekTimings[6];
 
<table class="table">
  <thead>
    <tr>
      <th>Sunday</th>
      <th>Monday</th>
      <th>Tuesday</th>
      <th>Wednesday</th>
      <th>Thursday</th>
      <th>Friday</th>
      <th>Saturday</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td id="sun"></td>
      <td id="mon"></td>
      <td id="tue"></td>
      <td id="wed"></td>
      <td id="thu"></td>
      <td id="fri"></td>
      <td id="sat"></td>
    </tr>
  </tbody>
</table>

Using Vue.js

You can iterate over the array using v-for and display the data

<td v-for="day in weekTimings">{{ day }}</td>

Hope this helps :)

2 of 3
2

You can modify your workHr to array of object, so it will be easier to iterate over them. For example

const workHour = "Monday :9:00AM to 5:00PM,Thuesday :9:00AM to 5:00PM,Wednesday :9:00AM to 5:00PM,Tuesday : 9:00AM to 5:00PM,Friday :9:00AM to 5:00PM,Saturday :9:00AM to 5:00PM,Sunday :9:00AM to 5:00PM".split(',').map((val) => { 
  const obj = val.split(':');
  const time = val.replace(`${obj[0]}:`, '');
  return {
    day: obj[0],
    time,
  }
});
console.log(workHour);

/*  following is the output of the code above
    [
      { day: 'Monday', time: '9:00AM to 5:00PM'},
      ........
    ]
*/

Then, you can assign workHour to data

data.workHr = workHour;

Then, it's easy to iterate over your table

<table class="table">
  <thead>
    <tr>
      <th v-for="(item,key) in data.workHr" :key="key">{{item.day}}</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td v-for="(item,key) in data.workHr" :key="key">{{item.time}}</td>
    </tr>
  </tbody>
</table>
🌐
Stack Overflow
stackoverflow.com › questions › 68287438 › how-to-display-json-keys-in-a-table-vuejs
How to display JSON keys in a table - VueJS
July 7, 2021 - <template> <div> <h1>My JSON</h1> <table> <tr v-for="b in jsondata['techniques'][0]['program']" :key="b.id"> <td>{{Object.keys(b)}}</td> <!-- <td v-for="check in folder.checks"> {{check.name}} </td> --> </tr> </table> </div> </template> <script> import cycleDescriptionData from '@/myjson.json' export default { name: 'myJSON', data() { return { jsondata: cycleDescriptionData, userInput: this.jsondata }; }, }; </script> The JSON I am trying to display is here: https://jsoneditoronline.org/#left=cloud.55f0755dbad64a7b95f1ab0725bd6a49&right=local.kaheka.
🌐
Stack Overflow
stackoverflow.com › questions › 74358032 › show-data-from-api-to-a-table-in-vue-js
vue.js - Show data from api to a table in vue js - Stack Overflow
What do you see in your Vue devtools? ... Also, I recommend that you use async mounted + await this.fetchDoctors(). ... "Am also trying to implement the routing such that when one clicks the button on the Actions column it redirect to another page that has a specific user details", that one is probably for another question. ... <template> <v-data-table hide-actions flat :headers="headers" :items="doctors" :items-per-page="5"> <template v-slot:body="{ items }"> <tbody> <tr v-for="item in items" :key="item.id"> <td>{{ item.name }}</td> <td>{{ item.full_name }}</td> <td>{{ item.mobile }}</td> <td