Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

458
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!