[Fixed]-How to remove [ ] closed bracket in djagno rest framework output

1👍

The format you have requested is NOT valid JSON.

Currently you receive data in square brackets [] because you have a list of elements, ordered set of elements accessible by index. And this is valid JSON.

Curly brackets {} are used in dictionaries — sets of elements, accessible by keys.

So, if you want your elements to be placed in curly brackets, they should be put as values of some dictionary. But dictionary elements, of course, should have keys. I.e., data should like this:

{
    "0": {
        "id": 1,
        "fruit": "Pomegranate",
        "district": "Pune",
        "taluka": "Haveli",
        "revenue_circle": "Uralikanchan",
        "sum_insured": 110000.0,
        "area": 12200.0,
        "farmer": 1836
    },
    "1": {
        "id": 2,
        "fruit": "Guava",
        "district": "Pune",
        "taluka": "Haveli",
        "revenue_circle": "Uralikanchan",
        "sum_insured": 50000.0,
        "area": 1150.0,
        "farmer": 10
    }
}

But. The data you currently have are in valid JSON format and are generally OK.

Leave a comment