0

I have a list of flat JSON keys and values. I am trying to replace all the key values with empty strings

Here is my JSON.

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

    "Sunday": "Sunday",
    "Monday": "Monday",
    "Tuesday": "Tuesday",
    "Wednesday": "Wednesday",
    "Thursday": "Thursday",
    "Friday": "Friday",
    "Saturday": "Saturday",

    "Su": "Su",
    "Mo": "Mo",
    "Tu": "Tu",
    "We": "We",
    "Th": "Th",
    "Fr": "Fr",
    "Sa": "Sa",

    "January": "January",
    "February": "February",
    "March": "March",
    "April": "April",
    "May": "May",
    "June": "June",
    "July": "July",
    "August": "August",
    "September": "September",
    "October": "October",
    "November": "November",
    "December": "December",

    "Jan": "Jan",
    "Feb": "Feb",
    "Mar": "Mar",
    "Apr": "Apr",
    "May": "May",
    "Jun": "Jun",
    "Jul": "Jul",
    "Aug": "Aug",
    "Sep": "Sep",
    "Oct": "Oct",
    "Nov": "Nov",
    "Dec": "Dec"
}

So I want to keep the key names but replace all the key values with empty strings

eg "wl.label.accountPin": "Account PIN", should be "wl.label.accountPin": "",

What would be the best way to do this?

3 Answers 3

3

You json is not json but an Object. Furthermore, it's a one liner. Here's a a minimal reproducable example.

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]: ""}), {}));

Sign up to request clarification or add additional context in comments.

Comments

2

Simple solution

json = {YOUR_DATA};
Object.keys(json).forEach(function(key) {
    json[key] = "";
})

See JSFiddle here http://jsfiddle.net/1xo6pf8s/

Comments

0

Here you go, enjoy and have a good day :)

 var d = {
         'firstKey':'firstValue',
         'secondKey':'secondValue'
        }

for(i in d){
d[i] = ''
}
console.log(d)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.