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

460
Vistas
How to remove Square Bracket from JSON in JavaScript or in php?

I have some JSON data, it is apairing like this now

[
  [
    {
      'key': 'value'
    },
    {
      'key': 'value'
    }
  ]
]

What I want to do, is remove the second square bracket from here like this:

[
  {
    'key': 'value'
  },
  {
    'key': 'value'
  }
]

I've applied some algorithms in both PHP and javascript but it does not work please help me if you know how to solve this

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the array_merge() PHP method like this (PHP 7.4 or above)

EDIT: Decode the JSON string using json_decode() php function before.

$flattened_array = array_merge(...$arr);

https://wiki.php.net/rfc/spread_operator_for_array

https://www.php.net/manual/pt_BR/function.array-merge.php

Or simply do this:

$arr = "[
  [
    {
      'key': 'value'
    },
    {
      'key': 'value'
    }
  ]
]" //receives a JSON string;

$flattened_arr = json_decode($arr[0]) //decodes it;
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