Unable to transform object into a primitive value using imported JSON data

I am currently working on creating a Vuetify component dynamically within a Nuxt project, as discussed in this Stack Overflow thread (Using different text values with Vuetify component). To achieve this, I am importing and iterating through JSON data stored in a module, as detailed in this Hacker Noon article ().

The contents of my /static/info.json file are as follows:

{
  "id": 1,
  "name": "Johnson, Smith, and Jones Co.",
  "amount": 345.33,
  "Remark": "Pays on time"
}

Within my Vue component, I have implemented the following code:

import * as data from '../static/info.json';

const companyName = data.name;

console.log(companyName); // output 'testing'
console.log(data); // output 'testing'
var jsonData = JSON.parse(data);
// console.log(jsonData); // output 'testing'

However, I encountered an issue with the line:

var jsonData = JSON.parse(data);

This resulted in the error message:

 Cannot convert object to primitive value 

Can anyone provide guidance on how I can effectively iterate through the imported JSON data?

Answer №1

It seems like the data has already been parsed into an object, so there's no need to parse it again. When you imported it, it was transformed into an object. You can access its properties directly using data.name

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

JavaScript opacity adjustments not achieving desired outcome

My attempt to make this sub menu fade in and out upon button press is not working as expected. It should fully fade in shortly after clicking 'help' and completely fade out when clicking 'back'. Is the problem with the method I'm u ...

I prefer to avoid using the "#" sign in URLs

<a href="#" onClick="load_page()">intro</a> I am trying to avoid displaying the # sign in the URL, and I would like it to appear like this instead: www.mydomain.com/ However, it currently displays as follows: www.mydomain.com/# Is there a ...

Utilizing a server for seamless communication between a mobile device and a website

Exploring a simple setup idea here: Imagine having a mobile app with a page that contains 4 lines of content (utilizing phonegap for development). The plan is to have a web page where data for those 4 lines can be inputted. Once the information is submitt ...

Error message: The 'Access-Control-Allow-Origin' policy is preventing access in a react express docker application

I have successfully set up a front-end React application and a Node/Express API using Docker. The React app is currently running on localhost:3000, while the API is running on localhost:9000. Both applications are fully functional. However, I am encounteri ...

What is the best way to showcase search outcomes using ajax in a Django project?

In my current Django project, I am developing a feature that allows users to search for a name using a form. The view will then search for that name in the database after some transformation and display the results below the form. Currently, the entire pa ...

The trouble with dynamicHelpers in Nodejs Express

Trying to make my app run smoothly, I've set up the following configurations: app.configure(function(){ app.set('views', __dirname + '/views'); app.enable('jsonp callback'); app.set('view engine', 'j ...

A Guide to Retrieving HTML Content Using jQuery's Ajax Method

I am working on a page that contains Option elements with Values linking to external pages. My goal is to utilize Ajax to retrieve the selected Option's Value and use it to load content from those external pages. For example, if a user selects Volleyb ...

Capturing numerous data points with JavaScript

<span> <label class="label">Color</label> <span class="foo"><input name="Color" value="Blue" class="customs" maxlength="100" type="text"/></span> </span> </span> <span> <label cla ...

Once the image has been observed, what steps can be taken to close it?

I wish to implement a functionality where clicking on the view button will enlarge the image, and another click on the page will return it to its original size. import * as React from 'react'; import Box from '@mui/material/Box'; imp ...

Tips for concealing dynamically generated div elements within a VueJS v-for loop

Is there a way to hide dynamically generated div elements in VueJS? In my chatbot application, messages are passed through a prop called messages. These message arrays create multiple Divs on the screen displaying information. One particular Div is used to ...

Is there a way to create an infinite fade in/out effect for this?

Is there a way to ensure that the method runs after the "click" event in this code snippet? The code currently fades in and out the div #shape while the start variable is true, but when I call the "start" method from the "click" event, the browser stops wo ...

Setting up environments utilizing restify

Having experience with gulp, I am well-versed in setting up a distinct configuration for each environment within a single configuration file. This allows for running gulp dev to initiate the server using the development environment configuration, gulp stag ...

Querying Quandl API with Node.js using HTTPS Request

My current project involves developing a web service using IBM Bluemix for a school assignment. The core requirement for my project is to retrieve JSON data from two distinct APIs to be integrated into the project's functionality. The initial API re ...

Attempting to send a POST request, only to be informed by the form that it is devoid of

I have been struggling with this problem for some time now. I implemented the category_create_post functionality in the categoryController, and everything seems to be set up correctly. I also configured the category_form.ejs to accept user input. However, ...

Utilizing AngularJS: Establishing a Universal Parent State in UI-Router for Modals and Shared Components

In my code using UI-Router and Bootstrap-ui modal, I have defined the state as shown below. reference var state = { name: 'modala', parent: 'home', onEnter: function($modal, $state) { modalInstance = $modal.open({ ...

Is Spring JdbcTemplate capable of cleaning URLs?

During the development of a Spring Boot API, I encountered a small issue that I could use some advice on from someone more experienced with how Spring Boot functions behind the scenes. Within a controller, there is a method marked with @ResponseBody that ...

What is the best way to set a boolean value for a checkbox in a React project with Typescript?

Currently, I am working on a project involving a to-do list and I am facing an issue with assigning a boolean value to my checkbox. After array mapping my to-dos, the checkbox object displays 'on' when it is unchecked and a 'Synthetic Base E ...

Showing a DIV multiple times with an additional text field in HTML and JS

As someone new to development, I am facing a requirement where I need to create a form with a dynamic field that can be added or removed using buttons. When the user clicks on the Add button, another field should appear, and when they click on Remove, the ...

Prevent parent element from changing color when child element is clicked

Check out my HTML: .imageURL:active .image_submit_div { background-color: #ccc; } .image_submit_div:active { background-color: #e6e6e6; } <div class="image_div"> <label for="id_image" class="image_submit_div"> <h3>+ add ...

Troubleshooting: Jquery UI Draggable - Cursor losing track of draggable element

I want to create a draggable popup with Jquery UI functionality, but I'm facing an issue where the cursor does not stay aligned with the popup element when dragged. When dragging the popup element to the left, the mouse cursor goes beyond the div elem ...