Hello! There is an objectT.txt file containing a JSON line:

{ "noData":false, "activity_empty":"No Data", "one":[ {"Id":"111222", "image_visible":true, "image":"ic_new.png", "tv_Id":"123456", "tv_pay":"2,700", "tv_Date":"jan 26 4:15 PM", "tv_deliveryDate":"jan 30 4:15 PM", "tv_source":"Edwardskkk, IL", "tv_destination":"Buckeye, AZ", "activity_weight":"Weight", "tv_weight":"4000", "activity_miles":"Miles", "tv_miles":"1234"}, {"Id":"222222", "image_visible":false, "image":"ic_new.png", "tv_Id":"123456", "tv_pay":"2,700", "tv_Date":"jan 26 4:15 PM", "tv_deliveryDate":"jan 30 4:15 PM", "tv_source":"Edwardskkk, IL", "tv_destination":"Buckeye, AZ", "activity_weight":"Weight", "tv_weight":"4000", "activity_miles":"Miles", "tv_miles":"1234"} ] } 

then we translate this line into objectT object, how to add a NEW field in objectT object, how to add a NEW field to the array one of objectT object (objectT.one), maybe you do not need to translate a string into an object, but to manipulate it?

  jQuery.get('objectT.txt', {} ,function(obj) { objectT = obj; objectT = JSON.parse(objectT); //Добавление к objectT нового поля //Добавление к objectT.one нового поля var myJSONText = JSON.stringify(objectT); jQuery('#id-container').append( myJSONText ); }, 'text') 

What would be the following:

  { "noData":false, "activity_empty":"No Data", "NEW_FIELD":"NEW_FIELD", "NEW_FIELD":"NEW_FIELD", "one":[ {"NEW_FIELD":"NEW_FIELD", "Id":"111222", "image_visible":true, "image":"ic_new.png", "tv_Id":"123456", "tv_pay":"2,700", "tv_Date":"jan 26 4:15 PM", "tv_deliveryDate":"jan 30 4:15 PM", "tv_source":"Edwardskkk, IL", "tv_destination":"Buckeye, AZ", "activity_weight":"Weight", "tv_weight":"4000", "activity_miles":"Miles", "tv_miles":"1234"}, {"NEW_FIELD":"NEW_FIELD", "Id":"222222", "image_visible":false, "image":"ic_new.png", "tv_Id":"123456", "tv_pay":"2,700", "tv_Date":"jan 26 4:15 PM", "tv_deliveryDate":"jan 30 4:15 PM", "tv_source":"Edwardskkk, IL", "tv_destination":"Buckeye, AZ", "activity_weight":"Weight", "tv_weight":"4000", "activity_miles":"Miles", "tv_miles":"1234"} ] } 

    1 answer 1

    It is possible so:

     objectT.NEW_FIELD = 'NEW_FIELD'; 

    or so:

     objectT['NEW_FIELD'] = 'NEW_FIELD';