How do I remove the extra square bracket from JSON having multiple arrays

how to remove square brackets from json array in java
remove bracket from array javascript
remove square brackets from json php
remove square brackets from json python
json stringify remove curly braces
json array without brackets
json starts with square bracket
jq remove square brackets

I am trying to get JSON from an array but I am getting an extra square bracket in the output.

I tried using $episode[0] = $podcast->getPodcastByCategoryId($id); but it only gives the incomplete output means it gives data of the first iteration from the array. And if I remove [] from $episode that also gives the data of first iteration.

$podList = $category->getCategoryPodcast();

if ($podList) {

    foreach ($podList as $items) {

        $id = $items->id;

        $episode[] = $podcast->getPodcastByCategoryId($id); 

    } 

}

echo json_encode($episode);

I expect to have only one square bracket but I am getting the output with two square brackets.

This is the out I am receiving from the above code:

[
[
    {
      "id": "6",
      "title": "Types of loops in PHP.",
      "description": "s.kfjhsdlufdgf o",
      "duration": "0:05:05",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-2019011511270942.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190115112709469.jpg",
      "category": "2",
      "added_date": "माघ १, २०७५",
      "category_title": "उमेर",
      "author": "John Doe",
      "episodes": "2"
    },
    {
      "id": "4",
      "title": "How to remove square brackets from JSON?",
      "description": "",
      "duration": "",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111541297.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190114102432145.jpg",
      "category": "2",
      "added_date": "पौष ३०, २०७५",
      "category_title": "उमेर",
      "author": "John Doe",
      "episodes": "2"
    }
  ],
  [
    {
      "id": "5",
      "title": "Hello World!",
      "description": "",
      "duration": "",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111937115.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190114104302103.jpg",
      "category": "1",
      "added_date": "पौष ३०, २०७५",
      "category_title": "गृह पृष्ठ",
      "author": "John Doe",
      "episodes": "1"
    }
  ]
]

According to the recommendation from @splash58 and @Vinesh Goyal, I am getting output like this:

[[
{
  "id": "6",
  "title": "Types of loops in PHP.",
  "description": "s.kfjhsdlufdgf o",
  "duration": "0:05:05",
  "audio": "http://demo.web/uploads/podAudio/PodAudio-2019011511270942.mp3",
  "image": "http://demo.web/uploads/podImage/PodImage-20190115112709469.jpg",
  "category": "2",
  "added_date": "माघ १, २०७५",
  "category_title": "उमेर",
  "author": "John Doe",
  "episodes": "2"
},
{
  "id": "4",
  "title": "How to remove square brackets from JSON?",
  "description": "",
  "duration": "",
  "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111541297.mp3",
  "image": "http://demo.web/uploads/podImage/PodImage-20190114102432145.jpg",
  "category": "2",
  "added_date": "पौष ३०, २०७५",
  "category_title": "उमेर",
  "author": "John Doe",
  "episodes": "2"
}
  ],

    {
      "id": "5",
      "title": "Hello World!",
      "description": "",
      "duration": "",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111937115.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190114104302103.jpg",
      "category": "1",
      "added_date": "पौष ३०, २०७५",
      "category_title": "गृह पृष्ठ",
      "author": "John Doe",
      "episodes": "1"
    }
]

but, what about the square brackets of first data?


You can merge arrays while getting

$episode = array_merge($episode, $podcast->getPodcastByCategoryId($id)); 

Or flatten the result array before converting to json

echo json_encode(array_merge(...$episode));

demo

Remove Square Brackets from JSON, I'm having difficulties to remove an additional set of square brackets or avoid including them within  Remove Square Brackets from JSON - WITHOUT_ARRAY_WRAPPER Option. 06/03/2020; 2 minutes to read +2; In this article. Applies to: SQL Server (all supported versions) Azure SQL Database. To remove the square brackets that surround the JSON output of the FOR JSON clause by default, specify the WITHOUT_ARRAY_WRAPPER option. Use this option with a single-row result to generate a single JSON object as output instead of an array with a single element.


Following snippet using javascript .concat() . Does this fit your desired output?

var data = [[
    {
      "id": "6",
      "title": "Types of loops in PHP.",
      "description": "s.kfjhsdlufdgf o",
      "duration": "0:05:05",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-2019011511270942.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190115112709469.jpg",
      "category": "2",
      "added_date": "माघ १, २०७५",
      "category_title": "उमेर",
      "author": "John Doe",
      "episodes": "2"
    },
    {
      "id": "4",
      "title": "How to remove square brackets from JSON?",
      "description": "",
      "duration": "",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111541297.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190114102432145.jpg",
      "category": "2",
      "added_date": "पौष ३०, २०७५",
      "category_title": "उमेर",
      "author": "John Doe",
      "episodes": "2"
    }
  ],
  [
    {
      "id": "5",
      "title": "Hello World!",
      "description": "",
      "duration": "",
      "audio": "http://demo.web/uploads/podAudio/PodAudio-20190114111937115.mp3",
      "image": "http://demo.web/uploads/podImage/PodImage-20190114104302103.jpg",
      "category": "1",
      "added_date": "पौष ३०, २०७५",
      "category_title": "गृह पृष्ठ",
      "author": "John Doe",
      "episodes": "1"
    }
  ]
];
var mergedData = data[0].concat(data[1]);
console.log(mergedData)

Return JSON array without extra square brackets, I have one json array object and i need to extract one particular value out of it, i used JSONPATH to  1 Remove <p> tag from HTML content Feb 15 '19 1 COUNT function in sql counting whole data in database Jan 28 '19 1 How do I remove the extra square bracket from JSON having multiple arrays Jan 29 '19


according to your code, $podcast->getPodcastByCategoryId($id); returning a array so t0 remove the issue you can use array_merge function

$podList = $category->getCategoryPodcast();
$episode = [];
if ($podList) {

    foreach ($podList as $items) {

        $id = $items->id;

       $episode = array_merge($episode, $podcast->getPodcastByCategoryId($id)

    } 

}

echo json_encode($episode);

I hope it will help you :)

How to remove square bracket and double quotes from extracted , To remove the square brackets that surround the JSON output of the FOR JSON clause Did you even try with them? share | improve this answer The brackets denote a JSON array, containing The "extra" brackets are not the only problem. Actually, I'm adding data into List<string> and add those List<string> values in Newtonsoft JSON object. But, when the result cames its become double brackets above the response. I've to replace double square brackets into one square brackets. Please find my code below, and advise me on this. Code :


Remove square brackets from json, Arrays use square bracket notation with comma-separated elements. If you use this option with a multiple-row result, the resulting output is not valid JSON Remove Square Brackets From Json. Python | Remove square brackets from list Sometimes, while working with displaying the contents of list, the square brackets, both opening and closing are undesired. For this when we need to print whole list without accessing the elements for loops, we require a method to perform this.


Json Array Without Square Brackets, Using JSON_TABLE on an array that starts with a square bracket, Mendoza, Lynelle I. - Arrays are created by adding  JSON arrays are specified using square brackets. XML arrays are represented by repeating an element name multiple times. XML arrays can also be represented as zero or more elements of the same name wrapped in another element: <Languages> <item>JavaScript</item> <item>Java</item> <item>Python</item> </Languages> Conversion:


Json square brackets curly brackets, In that case with multiple segments how can I remove square bracket and an extra curly bracket. Thanks, JSON Uses JavaScript Syntax. Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript. With JavaScript you can create an object and assign data to it, like this: