Transforming JSON into a JavaScript object containing only values

Seeking guidance on converting JSON values to an Object without the keys. How can this be achieved?

The JSON data in question is:

[
{
  "WebsiteName": "Acme Inc.",
  "Time": "08:30:00",
  "TheDate": "2021-12-23",
  "Hits": "39"
},
{
  "WebsiteName": "Acme Inc.",
  "Time": "08:45:00",
  "TheDate": "2021-12-23",
  "Hits": "37"
}
]

The desired format, excluding the names, is as follows:

var myObject = [["Acme Inc.", "08:30:00", "2021-12-23", "39"], ["Acme Inc.", "08:45:00", "2021-12-23", "37"]];

This transformation needs to be generic so that it can be applied to other JSON files in the future without modification.

Answer №1

One way to tackle this is by using the .map method along with Object.values:

let jsonData = `[
{
  "Company": "Tech Corp.",
  "Time": "10:30:00",
  "Date": "2021-09-15",
  "Visits": "75"
},
{
  "Company": "Tech Corp.",
  "Time": "10:45:00",
  "Date": "2021-09-15",
  "Visits": "70"
}
]`;

let processedData = JSON.parse(jsonData).map(item => Object.values(item));

console.log(processedData);

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

Vue 3: Leveraging Functions Within Mutations.js in Vuex Store to Enhance Functionality

In my mutations.js file, I have encountered a situation where one function is calling another function within the same file. Here's an example of my code: export default { async addQuestionAnswer(state, payload) { alert(payload); this.update ...

Creating a hexagon pattern within an array

I'm in need of assistance in writing a function that can generate a hexagon pattern within a 2D array. I only have the column size of the array, and the rest of the dimensions must be calculated. https://i.sstatic.net/WHuYF.png Unfortunately, I&apos ...

extract keys and values from an array of objects

I would like assistance with removing any objects where the inspectionScheduleQuestionId is null using JS. How can we achieve this? Thank you. #data const data = [ { "id": 0, "inspectionScheduleQuestionId": 1, ...

Is there a way to incorporate animation while calculating a number?

I am looking to add some special animation effects to the number in this script, but I am not sure how to achieve that. $('#choose').change(function() { if($(this).val() == '1') { document.getElementById('harga&ap ...

Parsing JSON data from a UITableView to a detailed view using AFNetworking

I successfully extracted data from the YouTube API and displayed it on a UITableView using AFNetworking. However, I'm stuck on how to utilize the didSelectRowAtIndexPath:(NSIndexPath *)indexPath method. Does anyone know how I can transfer the JSON da ...

Tips for handling Ajax urlencode in PHP

I'm facing an issue with a problem and need some assistance to resolve it. Currently, I am attempting to utilize Ajax urlencode in PHP, but the POST content is not being displayed by PHP as expected when HTML is sent directly to PHP. The following c ...

What is the best way to adjust the priority of elements using JavaScript in an ASP.NET MVC application?

As part of my application, I need to create a function that allows for the changing of deputy priorities for each consultant. Here is what I have implemented so far: View: @model ML.Domain.DAL.DB_CONSULTANTS .... <table> <tr> < ...

Tips for transforming a UTF16 document into a UTF8 format using node.js

My dilemma involves an xml file that is encoded in UTF16, and I need to convert it to UTF8 for processing purposes. When I use the following command: iconv -f UTF-16 -t UTF-8 file.xml > converted_file.xml The conversion process goes smoothly with the ...

Golang runtime: goroutine stack surpasses the 1 billion byte limit

Encountering an error while attempting to Marshall a nested struct object. The struct setup is as follows: type Blockchain struct{ blocks []Block `json:"blocks"` difficulty int `json:"difficulty"` } type Block struct{ index ...

Issue with jquery curvy corners not functioning properly on Internet Explorer 8

Check out my website at If you view the page in IE8 and then in IE7 compatibility mode, you'll notice a strange issue. The box on the right disappears in IE8 but displays perfectly rounded corners in IE7. I am currently using the jQuery Curvy Corner ...

Experience the power of CanJS Observable data objects with the added feature of

When working with canJS Observable, I encountered an issue where I cannot use dots in object keys because canJS interprets them as nesting. For example, if I try to create a new observable like this: var obs = new can.Observe( { "div.test-class": { "color ...

Accessing a JSON file over a network using JavaScript

Struggling to access a basic data file using JavaScript, and it's proving to be quite challenging. The file will be hosted on a remote server and ideally accessed via HTTP. While I'm new to JavaScript, I've come across JSONP as a potential s ...

Waiting in Python using Selenium until a class becomes visible

Currently, I am trying to extract information from a website that has multiple web pages. This is how my code appears: item_List = [] def scrape(pageNumber): driver.get(url + pageExtension + str(pageNumber)) items = driver.find_elements_by_class_ ...

Making adjustments to a variable through the use of Ajax

I'm currently diving into the world of Ajax and eager to learn more. Can anyone assist me in displaying a dynamic variable? rdm = urandom.randint(10,100) //generated from a loop in micropython. Here's my progress so far: I've successfull ...

What is the process of converting Luxon DateTime format into a string or numerical representation?

After setting up a Luxon clock for my project, I am facing an issue while using a component to define the month number of the current date. import { DateTime } from 'luxon'; import React, { useEffect, useState } from 'react'; interface ...

How to change the date value in an HTML input field of type date using JavaScript

Struggling with manipulating an HTML date input type using javascript? You're not alone. The common approach to manipulating the date is like this: var c = new Date(); c.setDate(c.getDate() + 1); You can get the date from the input element: c = do ...

Navigate to the end of a container

Is there a method to automatically scroll to the bottom of a div when the page is loaded? I have attempted several solutions without success. If you have any insights, please share them. Thank you! ...

I am having trouble understanding why my JavaScript code is bypassing the if statements

let emptyErr = [] if (!(req.body.title)) { emptyErr[0] = ('A title must be provided for a post!') } else if (!req.body.category) { emptyErr[1] = ('Please select a category for your post.') } else if (!req.body.content) { ...

Android experiencing issues with JSONObject truncation

As I work on connecting my application to the Salesforce API and retrieving all existing Contacts, I have encountered an issue. The response JSON object includes a key named "totalSize" indicating 33231 records, however, when attempting to access these rec ...

Generating an Array of Meshes Using Objects in THREE.JS and GLTF Format

Here is the code snippet I have for loading a mesh onto an object. Currently, it is iterating through the entire mesh. Code snippet: var loader = new THREE.GLTFLoader(); loader.load( '../gtf/Box.gltf', function ( gltf ) { ...