Finding ways to efficiently extract data from JSON files and accurately constructing the desired output according to my specifications

I have retrieved an object from JSON data.


{
  skills: {
    extracted: [
      {value: 'PHP'},
      {value: 'JavaScript'},
      {value: 'Python'}
    ]
  },

  experience : {
    jobs : [
      {
        date_range : {
          value : "September 2014 to January 2015"
        },
        company : {
          value : "Direct Skill Systems LLC"
        },
        title : {
          "value" : "Senior "
        }
      },
      {
        date_range : {
          value : "October 2013 to January 2014"
        },
        company : {
          value : "Seven Smarts LLC"
        },
        skills : [
          {
            value : "C#4 "
          }
        ]
      },
      {... details of other job experiences ...}
    ]
  },

  education: {
    institutions: [
      {
        name: {
          value: "American University"
        },
        date_range: {
          value: "July 2000 - November 2000"
        }
      },
      {... details of other educational institutions ...}
    ]
  }
}

How can I map the data from JSON and organize the result as described below?


{
  children: [
    {
      name: 'Skills',
      children2: [
        {name: 'PHP'},
        {name: 'JavaScript'},
        {name: 'Python'}                   
      ]
    }
  ]
}

I found help in the answer provided by Jamiec.


var input = {
  // Input JSON data here...
};

var data = {
  children: [
    {
      name: 'Skills',
      children2: input.skills.extracted.map(skill => ({name: skill.value}))
    },
    {
      name: 'Experience',
      children2: input.experience.jobs.map(job => ({name: job.date_range.value}))
    },
    {
      name: 'Education',
      children2: input.education.institutions.map(edu => ({name: edu.name.value, children2: [{name: edu.date_range.value}]}))
    },
  ]
};

console.log(data);
      

Answer №1

If you're looking to transform the skills.extracted array using the map function, you can follow this approach:

var data = {
  skills: {
    extracted: [
      {name: 'HTML'},
      {name: 'CSS'},
      {name: 'React'}
    ]
}

var result = {
        categories: [
            {
                type: 'programming',
                children: data.skills.extracted.map(skill => ({type: 'language', name: skill.name}))
            }
       ]
    }
    
console.log(result);

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

AngularJS Login Popup with SpringSecurity

I have successfully integrated spring security with my AngularJS webpage utilizing Rest API. However, I am facing an issue where every time I attempt to log in using the rest api from my customized login page, it prompts me for the login credentials in a p ...

Issue arising when attempting to dynamically load an image using Vue and Webpack

I recently set up an application using the Vue CLI, and within one of my components, I have included the following code snippet: <template> <div v-loading="loading"> <el-carousel :interval="4000" type="card" height="350px"> & ...

Validating forms in React with Material-UI using hooks

Currently, I am working on a Next.js project that utilizes Material-UI as the primary UI framework. For validation purposes, I am implementing a React hooks form. Within my main component, I have the form structure with separate child components for vari ...

When accessing files.fileName.path in formidable, it may result in returning undefined

The server is unable to save the file. The path property is giving back an undefined value. const saveImage = (req, res) => { const form = formidable.IncomingForm(); form.uploadDir = `./images`; form.keepExtensions = true; form.parse(req, (er ...

How to Insert Key-Value Pairs into CKEditor Selection Element

According to the documentation, to include a select element with distinct keys and values, you can follow this format: { id: 'my-element-id', type: 'select', label: 'My element', items: [ { value: &ap ...

Exploring the depths of Android Internal Storage: The perfect guide to efficiently parsing a JSON text file

I am in the process of developing an Android application that generates a text file containing JSON objects and saves it to internal storage. Below is the code snippet that accomplishes this task: JSONObject myJSON = new JSONObject(); //Populate the JSON ...

Guide to accessing a server file directly from the client's web browser

Hey Team, I have a requirement for the browser to read a property file from the server. To achieve this, I am using JQuery/AJAX as shown below. <script> var properties = null; $(document).ready(function(){ $.ajax({url:"demo_test.txt",success:fun ...

Using ng-repeat to locate the position of three-dimensional objects

Looking to achieve a final result similar to the illustration attached in the link provided. Each block in the picture is its own PNG image drawn using Illustrator and assigned with a specific CSS class. The challenge I am facing is how to position each i ...

Unable to display varied content in modal table

I'm facing an issue with my two bootstrap tables. The first table, table_compras, triggers a modal (table_modal) based on the clicked column. However, I am struggling to refresh the content rows in the table. Here is the code snippet: HTML: <div ...

Running a child process in the browser using Node.js with the help of browserify

Utilizing browserify to enable node.js functionality in the browser, I am attempting to run a child process in my index.js file: var exec = require('child_process').exec; //Checking the installed node version var ls = exec('node -v', f ...

Including tabs from a different HTML page within a tab on my own HTML page - enhancing the user interface of a web application

I am currently developing a web application with 4 tabs. Each tab includes a side menu (created using jQuery) and the rest of the space is divided into two sections: top div and bottom div (a table with two columns - column 1 contains the side menu, and co ...

What are the steps to transmit post data containing PHP source code with symbols such as (+, *, /, -) and save this information to a file using an AJAX request?

Currently, I am working on a web application that resembles w3schools' "Try it yourself!" feature. For now, I am focusing on the core functionality of the application without considering security measures. My Approach is : Getting user input throug ...

Can I change the name of an item in ngRepeat?

When repeating in a view: ng-repeat="item in list" In some scenarios, the 'item' looks like this: { "name": "john", "id": 1 } While in others, it appears as: { "value": { "name": "john", "id": 1 } } Is there a way to rena ...

The Gaussian Pyramid Overflow

I am currently working on creating my own Gaussian pyramid using c++. Following the reduce and expand equations outlined in the publication (equation 1 and 2), I encountered an issue with array index out of bounds when trying to access [2i + m][2j + n] ...

Instructions on importing a TSV file with a JSON field into Pig Latin

I'm trying to import a file that has a TSV schema with one field containing JSON values. Pig Latin's TextLoader handles tab-separated values, and JsonLoader is used for JSON data. Each row of the data looks like this: date\tevent_name&bsol ...

Navigating through Mongoose: Querying Data Based on Attribute Ranges

Help needed with making a MongoDB request using Mongoose. Looking to retrieve documents within a specific age range. For instance, I have a collection of cats along with their ages: [ { name: "cat1", age: 3 }, { name: "cat2", age: 2 }, { ...

I received no response when I checked my Discord messages

I'm currently working on creating a bot that will send a daily morning message at 9 o'clock with a customizable reaction. Right now, it's successfully sending the message on Discord but there seems to be an issue with the reaction part. Can ...

Monitoring transactions through interactive buttons that lead to external destinations

Tracking purchases on my website using a dynamic button that redirects to other sites is essential. See the code snippet below: <div class="buyproduct"> <a onclick="target='_blank'" href="<?php echo $this->product['from&apos ...

Executing a function that includes showModalDialog outside of an iframe might display the incorrect page

This website structure looks like: `--main.html `--dialog.html `--folder `--iframe.html The code for each page is as follows: main.html: <html> <head> <script type="text/javascript"> function t ...

What's the most effective strategy for transforming and preserving a nested JSON file as a MongoDB record?

Dealing with a massive JSON file (about 1.8GB) that I want to utilize in an Express app has proven to be challenging, given that Node's import limit is set at 512MB. Despite being new to MongoDB and databases in general, it seems like transitioning to ...