Navigating data in a Json array object

Can someone assist me in retrieving data from a JSON array file stored at the following link?

  Html
  <div>
    <div v-for="data in myJson.id " >{{ data }}</div>
  </div>
      js
    import json from '.././json/data.json'
      export default {
    components: {
      MainLayout,
    },
  data: function(){
        return {
          myJson:json
        }
      },
  method:{
    getjson:function(){
      this.json = JSON.parse(myJson);
    }
  }
  }

I need to retrieve specific data only by using the unique ID, but I'm having trouble with the current syntax.

Click to https://i.sstatic.net/8TX6B.png access the JSON file

Answer №1

It appears that there is no need to use JSON.parse. The functionality works fine without it. Simply place your JSON file in the same directory as your component and give this a try:

import data from './data.json'

export default {
  created () {
    for (const item of data[0]['file']) {
      console.log(`
        Name: ${item.name}
        Type: ${item.type}
        Size: ${item.filesize}
        Dimensions: ${item.dimension[0].width}x${item.dimension[0].height}
      `)
    }
  }
}

Upon loading the page, you will find information from your JSON file displaying in the console.

Answer №2

    <script>
  import MainLayout from '../layouts/Main.vue'
  import json from '.././json/data.json'

  export default {
    components: {
      MainLayout,
    },
  data: function(){
    return {
     myJson: json[0].file
    }
  },
  method:{

    }
  }
</script>   

 html
  <div v-for="data in myJson">
    {{ data.name }}
    {{ data.filesize}}
    {{ data.dimension[0].width}}x{{data.dimension[0].height}}
  </div>

As I applied the code above, I customized and utilized it to suit my specific requirements, and it functioned correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to using AJAX to send a select tag value to a PHP script on the current page

Issue I am facing a problem where I need to utilize the select tag in order to choose a value and then send that value via an ajax call to a PHP script embedded within the same page. In my code, I have implemented the select tag and upon selecting a valu ...

"Building a dynamic form with ReactJS, Redux Form, and Material UI - Implementing an

Currently working on a nested form framework that utilizes the redux form and material UI framework. The components have been developed up to this point - https://codesandbox.io/s/bold-sunset-uc4t5 My goal is to incorporate an autocomplete field into the ...

Grab the source attribute of the <img> tag (identified by class) across numerous HTML pages

Here is an example: A website has the URL , where xxxx represents an integer between 1 and 1935. On each page, there may be an <img class="thumbnail" src="Images\Robots\{robotname}.png">. However, not all pages have th ...

Node.js readline: SyntaxError: Unexpected token =>

Currently, I am diving into node.js and have found myself in need of utilizing the readline module for a new project. Below is the code snippet that I extracted directly from the official readline module example. const readline = require('readline&ap ...

Combining two sets of data into one powerful tool: ngx-charts for Angular 2

After successfully creating a component chart using ngx-charts in angular 2 and pulling data from data.ts, I am now looking to reuse the same component to display a second chart with a different data set (data2.ts). Is this even possible? Can someone guide ...

Is there a way to arrange an array based on the product or quotient of two values?

I'm working with an array of posts, each containing data on 'views' and 'likes', along with the user IDs associated with those likes. My goal is to sort this array based on the like rate. However, my current approach seems to be i ...

Resulting JSON output retrieved from the database

Greetings! I have retrieved the JSON data below from my database: [{ "0": "1", "id": "1", "1": "Hakob", "name": "Hakob", "2": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee8f8c8dae8b838f8782c08d8183"> ...

Is it possible to incorporate a new method into a JSON object?

How can I incorporate a method into a JSON object? ...

Unable to retrieve the /socket.io/socket.io.js file in the client-side application

My server side application is currently hosted on heroku: The code snippet that is relevant to this issue is as follows: const express = require('express'), app = express(), server = require('http').createServer(app), ...

Ways to turn off emojis in froala editor

I successfully integrated the Froala editor and dynamically generated an ID for it based on specific requirements. Everything is working well, but I now need to disable emoticons in this editor. $('#froala'+key).froalaEditor({ imageUploadP ...

What is the reason behind CURLOPT_POSTFIELDS not supporting json_encode()?

CURLOPT_POSTFIELDS cannot handle json_encode, but if the JSON is directly inputted into CURLOPT_POSTFIELDS, it will result in an error: {"error":"bad_request","reason":"Request body must be a JSON object"} $bd = "fiscont_db_catalogo_cuentas"; $ch = cu ...

Managing promises with mongoose - Best practices

I am new to using mongoose and I am trying to figure out how to save and handle promises in Node.js using a mongoose schema. In the example below, I am attempting to save data to a collection and handle any errors that may occur. model.js var mongoose = ...

I am attempting to retrieve the information entered into the textbox, search for it within my database, and display the results beneath the textbox for reference

<!----- fetchCedulaData.php This script retrieves data from the database and performs a search to return results ---------------------------- - --> <?php require("connection.php"); $cedula=$_REQUEST["cedula"]; //$cedula="0922615646"; echo $cedu ...

Swap out a term in a sentence with an interactive span element in real-time

I'm struggling with a seemingly simple task, and I feel quite embarrassed that I can't seem to solve it. My goal is to identify words in a string that begin with '@' or '#' and change their color to blue. The string itself com ...

When attempting to compile at runtime without an instance, the act of creating a function constructor can lead to an

My website is designed to function as a simple quiz game. It retrieves an array of JSON questions using AJAX, and for each question in the array, it displays the question itself along with buttons containing various options that were stored in the question ...

What could be the reason behind the improper display of JavaScript for ID overlay2?

Why is it that when I try to have two overlays with different messages display upon clicking buttons, they both end up showing the same message? Even after changing the ID tag names, the issue persists. Can someone shed some light on what might be causin ...

Tips for implementing fetch in a GET request and displaying the outcomes on the screen

Currently, I am utilizing express router in Node for an endeavor to display a page with data retrieved from an API. Unfortunately, no results are returned, and I can confirm that the issue does not lie with the API itself. Upon manual inspection in the con ...

Do developers typically define all flux action types within a constants object as a common programming practice?

This question arises from an informative article on flux. The common approach involves defining all action types within a constants object and consistently referencing this object throughout the application. Why is it considered a common practice? What ...

Encountering issues with Vue SVGs post updating vue-cli and vue-svg-loader

We have implemented vue-svg-loader (latest version) in our project using the configuration file vue.config.js: const svgRule = config.module.rule('svg') svgRule.uses.clear() svgRule .use('babel-loader') .loader('babel ...

Navigating a path and executing unique functions based on varying URLs: A guide

I am trying to send a post request to the path /users and then right away send another post request to /users/:id. However, I need the actions to be different for each of these URLs, so I cannot use the array method to apply the same middleware. The goal ...