weerd2
weerd2

Reputation: 690

Modify JSON object

I have the following JSON object :

var myObject = {"priorityset": 
  [
    {"name":"Prio1", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}, 
    {"name":"Prio2", "valueA":"1", "valueB":"0", "valueC":"0", "valueD":"1"}, 
    {"name":"Prio3", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}
  ]
};

I want to modify this object so I get something like this:

var myObject = 
[
  {"name":"Prio1", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}, 
  {"name":"Prio2", "valueA":"1", "valueB":"0", "valueC":"0", "valueD":"1"}, 
  {"name":"Prio3", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}
];

I have tried to solve this by myself, but no solution so far. Any ideas?

Thanks in advance.

Upvotes: 0

Views: 2179

Answers (1)

hvgotcodes
hvgotcodes

Reputation: 120308

First, json is a string-based data format. You have an object literal with a property, the value of which is an array that contains object literals. From what I see, you just want the property.

myObject = myObject.priorityset;

Equally valid is

myObject = myObject['priorityset'];

which is another way to do property access on an object literal.

Upvotes: 3

Related Questions