vote up 2 vote down star
1

How do i add new attribute (element) to JSON object using javascript

flag
Accept the answer and close this question – Arun P Johny Sep 16 at 17:16

3 Answers

vote up 6 vote down

JSON stands for JavaScript Object Notation. A JSON object is really a string that has yet to be turned into the object it represents.

To add a property to an existing object in JS you could do the following.

object["property"] = value;

or

object.property = value;

If you provide some extra info like exactly what you need to do in context you might get a more tailored answer.

link|flag
vote up 2 vote down

A JSON object is simply a javascript object, so with Javascript being a prototype based language, all you have to do is address it using the dot notation.

   mything.NewField = 'foo';
link|flag
vote up -3 vote down

Thank you. It worked.

link|flag
2  
The courtesy here is to accept an answer. – Crescent Fresh Apr 10 '09 at 18:04

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.