Skip to content Skip to sidebar Skip to footer

How To Remove Square Bracket From JSON

I have one json string like below [ { 'Name': 'TEST', 'deviceId': '', 'CartId': '', 'timestamp': 1383197265540, 'FOOD': [], 'Ci

Solution 1:

Use this when you return:

return properties[0];

Or

var data = [

{
    "Name": "TEST",
    "deviceId": "",
    "CartId": "",
    "timestamp": 1383197265540,
    "FOOD": [],
    "City": "LONDON CA"
 }

]; // Or whatever the Json is
data = data[0];

Or if you're accessing the json via another object

var data = jsonObj[0];

Solution 2:

var tmpStr = '[    
    {
        "Name": "TEST",
        "deviceId": "",
        "CartId": "",
        "timestamp": 1383197265540,
        "FOOD": [],
        "City": "LONDON CA"
     }

]';

var newStr = tmpStr.substring(1, tmpStr.length-1);

See this codepen example


Solution 3:

Try This:

var A = [{}]; var B = {}; A = [

    {
        "Name": "TEST",
        "deviceId": "",
        "CartId": "",
        "timestamp": 1383197265540,
        "FOOD": [],
        "City": "LONDON CA"
     }

]

B = A[0]; console.log(B); //required output

Solution 4:

This should help:

.replace(/[[\]]/g, '')

Post a Comment for "How To Remove Square Bracket From JSON"