3
1

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

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

3 Answers

9

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
2

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
-5

Thank you. It worked.

link|flag
4  
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.