0
I am starting an application with Angular 8 and have a question that is being complicated to solve.
Is there a practical way to turn a javascript object into a JSON string defining which attributes of it I want to pass? For example: I fear the following Object
{
"id":null,
"nome":"Pedro de Lara",
"documento":"00000000000",
"fone1":"1234",
"municipio":{
"id":4861,
"nome":"Carlos Barbosa",
}
}
I would like this function to automatically transform the municipality so that it only has the id, for example:
{
"id":null,
"nome":"Pedro de Lara",
"documento":"00000000000",
"fone1":"1234",
"municipio":{
"id":4861
}
}
This example is a small object, but what I need to do is with larger "children" objects.
I’m sorry if the question is too silly, I’m new to the subject and I haven’t found an option that will convince me to be the best.
Thank you.
Good morning, then, I realized that I would have this circular problem, that’s when I decided to start looking for alternatives. I would need to transform this object to JSON, using JSON.parce?
– Gilvan André
No, manually, it’s like you take from this circular object only what you want. This lib lodash has _.pick, it is unlike _.omit, with this method you take only what you want from an object. Take a look here: https://lodash.com/docs/4.17.15#pick
– vmontanheiro