0
I have a JSON that looks like this:
[
{
"texto": "Eae",
"contato": "Luis",
"data": "2018-09-25T21:08:00"
},{
"texto": "Salve povo",
"contato": "Rogerio",
"data": "2018-09-25T21:15:00"
}
]
And an HTML component with a textarea
where the user would enter the text and the missing data such as contact and date are dynamically caught.
How do I add a "message" to JSON to make it look something like this:
[
{
"texto": "Eae",
"contato": "Luis",
"data": "2018-09-25T21:08:00"
},{
"texto": "Salve povo",
"contato": "Rogerio",
"data": "2018-09-25T21:15:00"
},{
"texto": "De boas?",
"contato": "Victor",
"data": "2018-09-25T21:09:00"
}
]
I am trying to use an internal and private variable, like Httpclient
this._http.get("../assets/db/mensagem.json");
?– Gunblades
I don’t get it, buddy. Wasn’t the problem adding an item to the array? Your comment suggests that the problem may be another, unrelated to the question. If this is the case, I suggest asking a new question, clarifying the problem, with example of minimum code that reproduces it.
– Leonardo Alves Machado
I need the dice typed (text) is played inside the JSON (the contact and date are taken dynamically by the application), for example I type "Hello" in the textarea and JSON should insert a new "message":
{
 "texto": "Olá", 
 "contato": "Victor", 
 "data": "2018-09-27T14:10:00"
 }
– Gunblades
If that’s it, the
Array.push
resolve. Just create an object with the desired elements and the text and push...– Leonardo Alves Machado
If you want to turn your object into text again, use the stringify
– Leonardo Alves Machado