Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
how to send a correct json to backend in angular

I am sending an array object which right now looks like this in my console:

[{

}]

but I want to have it like this:

{

}

Could someone tell me how to change it, to my desired form? this is how my documentsArray looks:

  documentsArray = [];

This is how my code looks like this:

uploadFile2(files: FileList | null): void {
        const file = files.item(0)
        const reader = new FileReader()
        reader.readAsDataURL(file)
        reader.onload = () => {
          this.documentsArray.push({documentType: this.form.controls.dokumentType.value, file: reader.result})
          console.log(this.documentsArray)
        }
    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can access an array item using the index position:

const foo = [{ bar: 'baz' }, { quz: 'qux' }];

console.log(foo[0]); // only first item: `{ bar: 'baz' }`

I.e.:

uploadFile2(files: FileList | null): void {
        const file = files.item(0)
        const reader = new FileReader()
        reader.readAsDataURL(file)
        reader.onload = () => {
          this.documentsArray.push({documentType: this.form.controls.dokumentType.value, file: reader.result});
          // you can use the first object in the array
          console.log(this.documentsArray[0]);
        }
    }

about 4 years ago · Juan Pablo Isaza Denunciar

0

JSON specification is this:

[{ array1 }, {array2}, {other arrays}]

And this is the standard whay, why you would like to go outside the standard method?? Please note that in future if you want excange data with oter platforms, you will rebuild everithing, cause json array is with [ ] and json decode will fail if you don't have it, if you don't know how to handle the [ ] just temporary delete the first and the last characters from the writing/reading string, but is not so good..

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda