3
I’m trying exhaustively to put a property on an object that comes from a request (JSON), but I’m not getting it, it’s like it just doesn’t, but when I do a console.log, there it is, but it’s not returning in the answer I send to Postman.
request(url, function (error, response, body) {
let result = JSON.parse(body);
result['teste'] = 'teste';
res.status(200).send(result);
});
Without the property he returns me so:
[
{
"prop1": "prop1",
"prop2": "prop2",
},
{
"prop1": "prop1",
"prop2": "prop2",
},
]
And I wanted him to return something like this to me:
[
{
"prop1": "prop1",
"prop2": "prop2",
},
{
"prop1": "prop1",
"prop2": "prop2",
},
"teste": "teste",
]
How do I stay that way up?
What are you trying to do after assigning the property? A new request?
– bfavaretto
@bfavaretto am picking up an external json from another url, I just want to add a property and return to the user as the request response.
– Lollorcaust
What is "return to the user"? Your code handles the return of that JSON and adds a property to the obtained object. The use of the object needs to be done from within this function (callback) that you already have.
– bfavaretto
@bfavaretto this code is a part of an api, in which case we make a request for this route that fetches information in an external api that returns a json to me, I need to treat by adding an extra field at the end of json as in the example and return the modified json.
– Lollorcaust
@Lollorcaust has already tried
result.push({teste: 'teste'});
?– NoobSaibot