Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace entire JSON file key values with empty strings

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

What would be the best way to do this?

>Solution :

Simple solution

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

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading