Update all the key values in the JSON file to be empty strings

Looking for a solution to modify the values in a list of flat JSON key-value pairs by replacing them with empty strings.

Below is an example of the JSON data:

{
    "wl.label.accountPin": "Account PIN",
    "wl.label.logon": "Logon details",
    ...
}

The goal is to retain the keys but blank out the corresponding values. For instance,

"wl.label.accountPin": "Account PIN"
should become
"wl.label.accountPin": ""
.

How can this task be efficiently accomplished?

Answer №1

Your data appears to be serialized as an object instead of proper JSON format. It is also represented on a single line, making it challenging to read and work with. For guidance on creating a minimal reproducible example, check out this resource.

const obj = {
    "wl.label.accountPin": "Account PIN",
    "Sunday": "Sunday",
    "Su": "Su",
    "January": "January",
    "Jan": "Jan",
};

console.log(Object.entries(obj).reduce( (acc, [key,]) => ({...acc, [key]: ""}), {}));

Answer №2

Straightforward solution

data = {YOUR_DATA};
Object.keys(data).forEach(function(prop) {
    data[prop] = "";
})

Check out the JSFiddle demo http://jsfiddle.net/abc123xy/

Answer №3

Here is a little gift for you to brighten your day :)

 let data = {
         'keyOne':'valueOne',
         'keyTwo':'valueTwo'
        }

for(item in data){
data[item] = ''
}
console.log(data)

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

Employ the setInterval function to run a task every 15 minutes for a total of

I have a task that requires me to use setInterval function 5 times every 15 minutes, totaling one hour of work. Each value retrieved needs to be displayed in an HTML table. Below is the table: enter image description here For example, if it is 7:58 p.m. ...

The maximum value of the slider corresponds to the total number of elements in the array

As I work on constructing a Material UI Slider, I have a specific requirement. I want the maximum value of my slider to dynamically adjust according to the number of items in an array of options. ['Answer1', 'Answer2', 'Answer3&ap ...

The transfer of information through HTTP

I have been exploring the inner workings of HTTP servers and clients to better understand how data is transmitted. Despite reading numerous articles on the topic, I still have some lingering questions that remain unanswered. I would like to walk through th ...

Manipulate Browser Navigation Behavior using JavaScript or AngularJS

How to Manage Browser Back Button Behavior Using AngularJS or JavaScript This is not a question, but rather a demonstration of how you can disable and manipulate the behavior of the browser's back button when using AngularJS or plain JavaScript. ...

JavaScript throws an error when attempting to access an object's methods and attributes

Within my Angular.js module, I have defined an object like this: $scope.Stack = function () { this.top = null; this.size = 0; }; However, when I try to use the push method of this object, I encounter an error stating undefined: ...

Python Selenium : Struggling to locate element using ID "principal"

As part of my daily work, I am currently working on developing a Python Script that can automate the process of filling out forms on various websites. However, I encountered an issue with Selenium while trying to interact with certain types of webforms. F ...

Instead of using onload, activate function upon click instead

Upon page load, I have a function that executes: function loadData(page){ showLoading(); $.ajax({ type: "GET", url: "load_data.php", data: "page="+page, success: function(msg) { ...

Incorporating React components into your current Django project

My goal is to enhance the interactivity of a specific part of my Django website by incorporating React components into the template HTML file. Instead of replacing the entire template with React, I want to focus on integrating React for its ease in handlin ...

Concealing the parent template in Vue Router when the child is displayed

Having some trouble setting up Vue.js with the router, specifically dealing with view display issues. I've created a router.js file with child routes for breadcrumbs and route clarity purposes. Each individual route loads perfectly fine when opened. ...

Discover a method to conceal an element within a <div> by monitoring mouseover events in a separate <div> container

<div id="one-id"> <div id="some">Information</div> <div id="control"> <div id="value-1"> <img id="image-one-id" /> <img id="image-two-id" /> ...

Tips for updating parent data with multiple values from a child component

Check out the code snippet below. I seem to be stuck on a crucial component. Despite going through the documentation and watching tutorials on Vue2, I can't seem to grasp this key element. Any assistance would be greatly appreciated. If my approach i ...

Using an Ajax Post Call to send FormData leads to a Get request instead

Having trouble with sending a simple form via POST method. I load the form content using AJAX: $(function() { var arg = { "operation": "upload", "step": "0" ...

Issue with formik onchange event not filling data in Material UI TEXTFIELD component

Greetings! I am currently working on a React project where I am managing the authentication process. I am using Material UI and Formik for validation and handling input changes. However, I encountered an issue with my onchange Formik handler in the TEXTF ...

Attempting to showcase the data stored within MongoDB documents on my website's user interface

I am facing difficulties in showing the data stored in my database on the front end of my grocery list app, which is built using the MERN stack. I have a form that successfully sends data to MongoDB and saves it upon submission. In order to retrieve the d ...

Creating a dynamic list filter using JavaScript and three select boxes

Looking for a way to implement a similar feature to the one on this webpage: I will be showcasing a list of brands on the page, with each brand requiring three pieces of information: Starting letter Store (multiple options) Category (multiple options) ...

Only one active class is allowed in the Bootstrap Accordion at any given time

I have implemented Bootstrap's accordion on my webpage, consisting of two different sections with unique content. Upon loading the page, the active class defaults to the first element of the first section. However, if I navigate to the "Second" sectio ...

When I try to add more content to my page, it doesn't extend beyond a single page and instead gets compacted together

As a beginner in the world of coding, my goal is to create a time management website specifically tailored for school use. Despite copying this code multiple times, I have encountered an issue where it does not continue down the page, and I am unsure of th ...

Combining Array Elements to Create a Unified Object with Vue

Is there a way to transform an array into a list of objects? Transform [ { "currenttime":43481.46983805556, "moped":"30 minutes", "car":"1 hour" } ] to { "currenttime":43481.46983805556, "moped":"30 minutes", ...

Utilizing _.partial on a single-argument function

Currently, I am in the process of refactoring code within a react.js application. There is an element that utilizes Underscore.js _.partial on a function that already has one argument. Is there any real benefit to doing this? I can see how it works based ...

The iPad screen displays the image in a rotated position while it remains

Recently, I developed a mini test website that enables users to upload pictures and immediately see them without navigating back to the server. It seemed quite simple at first. $('input').on('change', function () { var file = this. ...