0

i have a json string in the format

var jsonData =    [{"label":"Hass1(xxx_sem@hotmail.com)","value":"xxx_sem@hotmail.com"},{"label":"Hass(sxx_sem@hotmail.com)","value":"sxx_sem@hotmail.com"},{"label":"Sam(sx_sem@hotmail.com)","value":"sx_sem@hotmail.com"}]

i need to convert it in the format it into this way

var obj = {"Hass1(xxx_sem@hotmail.com)":"xxx_sem@hotmail.com",
          "Hass(sxx_sem@hotmail.com)","sxx_sem@hotmail.com"}

how to do so?

I have implemented so far like

function ConvertMeJason(jsonMe) {
            var list = JSON.parse(jsonMe);
            list.Object.forEach(function (obj) { /// I am getting error undefined function foreach
                emptyJson.add('"' + obj.label + '"', '"' + obj.value + '"');
            })
        }
Hassaan
  • 3,931
  • 11
  • 34
  • 67

1 Answers1

0

Something like this:

function convert(data) {
    var obj = {};
    for (var i = 0; i<data.length; i++) {
        obj[data[i].label] = data[i].value;
    }
    return obj;
}

Here is a JSFiddle.

Corey
  • 5,818
  • 2
  • 24
  • 37