How to save a json from a web API to the database?

I’m getting the following matrix:

 "QUALITY": [
                {
                    "cod": "xxxx",
                    "month": "10/2021",
                    "AVERAGE": [
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        }
                    ]
                },
                {
                    "COD": "XXXXXX",
                    "MONTH": "11/2021",
                    "AVERAGE": [
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        }
                    ]
                },
                {
                    "COD": "XXXXXX",
                    "MONTH": "12/2021",
                    "AVERAGE": [
                        {
                            "STATUS": "XXX",
                            "TYPO": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPO": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPO": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        },
                        {
                            "STATUS": "XXX",
                            "TYPE": "XXX",
                        }
                    ]
                },
                {
                    "COD": "P0001801",
                    "MONTH": "01/2022",
                    "AVERAGE": "----"
                }
            ],

I’m accessing “averages” like this. After getting the values, I try to get the “quality” values

averages = response.data.data[0].QUALITY[0].AVERAGE.map(a => ({ status: a.STATUS, type: a.TYPE}))
quality = response.data.data[0].QUALITY.map(a => ({ averages: [a.averages]}))

I did a console.log in “quality” and I get:

{ averages: [ undefined ] },
{ averages: [ undefined ] },
{ averages: [ undefined ] },
{ averages: [ undefined ] }

How can I access the information correctly and save it in the bank?

The template looks like this:

var averageSchema = new mongoose.Schema({
  status: [{
    type: String
  }],
  type: [{
    type: String
  }]
});
.
.
quality:[{
    averages: [{averageSchema}],
}]

In the controller, I save like this:

quality: 
[
{
    cod: COD,
    month: MONTH,
	averages: averages
}
]

I appreciate if someone helps me analyze!

One error is that the element a.averages does not exist either check the case (upper and lower, and also check if it is plural or not). It is case sensitive.

Try just

...QUALITY.map(a => ({ averages: a.AVERAGE})

because that seems to work in the first place.

Thanks for the feedback.

...QUALITY.map(a => ({ averages: a.AVERAGE})

This really helped, but it just prints the final “average”, which is not an array. The others are printed as [[Array]]

{
    averages: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  },
  {
    averages: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  },
  {
    averages: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object]
    ]
  },
  { medias: 'No data in the period.' }

The console does not print deeply nested objects. Use

const level=3 //tweak level.
console.log(JSON.stringify(myObject, null, level));

You could also use Postman or some client to send and receive data instead of logging the received data out.