Why is JSON with curly braces invalid?

Multi tool use
up vote
0
down vote
favorite
I'm trying to pass valid JSON to dataTables but any result that uses curly braces in the array is not accepted.
Working JSON Data[demo]:
"data":[
[
"Rhona Davidson",
"Integration Specialist",
"Tokyo",
55,
"2010/10/14",
"$327,900"
],
[
"Colleen Hurst",
"Javascript Developer",
"San Francisco",
39,
"2009/09/15",
"$205,500"
],
[
"Sonya Frost",
"Software Engineer",
"Edinburgh",
23,
"2008/12/13",
"$103,600"
],
[
"Jena Gaines",
"Office Manager",
"London",
30,
"2008/12/19",
"$90,560"
],
[
"Quinn Flynn",
"Support Lead",
"Edinburgh",
22,
"2013/03/03",
"$342,000"
],
[
"Charde Marshall",
"Regional Director",
"San Francisco",
36,
"2008/10/16",
"$470,600"
],
[
"Haley Kennedy",
"Senior Marketing Designer",
"London",
43,
"2012/12/18",
"$313,500"
],
[
"Jenette Caldwell",
"Development Lead",
"New York",
30,
"2011/09/03",
"$345,000"
],
[
"Yuri Berry",
"Chief Marketing Officer (CMO)",
"New York",
40,
"2009/06/25",
"$675,000"
],
[
"Caesar Vance",
"Pre-Sales Support",
"New York",
21,
"2011/12/12",
"$106,450"
],
[
"Doris Wilder",
"Sales Assistant",
"Sidney",
23,
"2010/09/20",
"$85,600"
],
[
"Angelica Ramos",
"Chief Executive Officer (CEO)",
"London",
47,
"2009/10/09",
"$1,200,000"
],
[
"Gavin Joyce",
"Developer",
"Edinburgh",
42,
"2010/12/22",
"$92,575"
],
[
"Jennifer Chang",
"Regional Director",
"Singapore",
28,
"2010/11/14",
"$357,650"
],
[
"Brenden Wagner",
"Software Engineer",
"San Francisco",
28,
"2011/06/07",
"$206,850"
],
[
"Fiona Green",
"Chief Operating Officer (COO)",
"San Francisco",
48,
"2010/03/11",
"$850,000"
],
[
"Shou Itou",
"Regional Marketing",
"Tokyo",
20,
"2011/08/14",
"$163,000"
],
[
"Michelle House",
"Integration Specialist",
"Sidney",
37,
"2011/06/02",
"$95,400"
],
[
"Suki Burks",
"Developer",
"London",
53,
"2009/10/22",
"$114,500"
],
[
"Prescott Bartlett",
"Technical Author",
"London",
27,
"2011/05/07",
"$145,000"
],
[
"Gavin Cortez",
"Team Leader",
"San Francisco",
22,
"2008/10/26",
"$235,500"
],
[
"Martena Mccray",
"Post-Sales support",
"Edinburgh",
46,
"2011/03/09",
"$324,050"
],
[
"Unity Butler",
"Marketing Designer",
"San Francisco",
47,
"2009/12/09",
"$85,675"
],
[
"Howard Hatfield",
"Office Manager",
"San Francisco",
51,
"2008/12/16",
"$164,500"
],
[
"Hope Fuentes",
"Secretary",
"San Francisco",
41,
"2010/02/12",
"$109,850"
],
[
"Vivian Harrell",
"Financial Controller",
"San Francisco",
62,
"2009/02/14",
"$452,500"
],
[
"Timothy Mooney",
"Office Manager",
"London",
37,
"2008/12/11",
"$136,200"
],
[
"Jackson Bradshaw",
"Director",
"New York",
65,
"2008/09/26",
"$645,750"
],
[
"Olivia Liang",
"Support Engineer",
"Singapore",
64,
"2011/02/03",
"$234,500"
]
]
Failing JSON Data (Demo):
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
Returns
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
The demo returns contents from a PHP file.
header("HTTP/1.1 200 OK");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
Any suggestions would be very appreciated.
php json datatables
add a comment |
up vote
0
down vote
favorite
I'm trying to pass valid JSON to dataTables but any result that uses curly braces in the array is not accepted.
Working JSON Data[demo]:
"data":[
[
"Rhona Davidson",
"Integration Specialist",
"Tokyo",
55,
"2010/10/14",
"$327,900"
],
[
"Colleen Hurst",
"Javascript Developer",
"San Francisco",
39,
"2009/09/15",
"$205,500"
],
[
"Sonya Frost",
"Software Engineer",
"Edinburgh",
23,
"2008/12/13",
"$103,600"
],
[
"Jena Gaines",
"Office Manager",
"London",
30,
"2008/12/19",
"$90,560"
],
[
"Quinn Flynn",
"Support Lead",
"Edinburgh",
22,
"2013/03/03",
"$342,000"
],
[
"Charde Marshall",
"Regional Director",
"San Francisco",
36,
"2008/10/16",
"$470,600"
],
[
"Haley Kennedy",
"Senior Marketing Designer",
"London",
43,
"2012/12/18",
"$313,500"
],
[
"Jenette Caldwell",
"Development Lead",
"New York",
30,
"2011/09/03",
"$345,000"
],
[
"Yuri Berry",
"Chief Marketing Officer (CMO)",
"New York",
40,
"2009/06/25",
"$675,000"
],
[
"Caesar Vance",
"Pre-Sales Support",
"New York",
21,
"2011/12/12",
"$106,450"
],
[
"Doris Wilder",
"Sales Assistant",
"Sidney",
23,
"2010/09/20",
"$85,600"
],
[
"Angelica Ramos",
"Chief Executive Officer (CEO)",
"London",
47,
"2009/10/09",
"$1,200,000"
],
[
"Gavin Joyce",
"Developer",
"Edinburgh",
42,
"2010/12/22",
"$92,575"
],
[
"Jennifer Chang",
"Regional Director",
"Singapore",
28,
"2010/11/14",
"$357,650"
],
[
"Brenden Wagner",
"Software Engineer",
"San Francisco",
28,
"2011/06/07",
"$206,850"
],
[
"Fiona Green",
"Chief Operating Officer (COO)",
"San Francisco",
48,
"2010/03/11",
"$850,000"
],
[
"Shou Itou",
"Regional Marketing",
"Tokyo",
20,
"2011/08/14",
"$163,000"
],
[
"Michelle House",
"Integration Specialist",
"Sidney",
37,
"2011/06/02",
"$95,400"
],
[
"Suki Burks",
"Developer",
"London",
53,
"2009/10/22",
"$114,500"
],
[
"Prescott Bartlett",
"Technical Author",
"London",
27,
"2011/05/07",
"$145,000"
],
[
"Gavin Cortez",
"Team Leader",
"San Francisco",
22,
"2008/10/26",
"$235,500"
],
[
"Martena Mccray",
"Post-Sales support",
"Edinburgh",
46,
"2011/03/09",
"$324,050"
],
[
"Unity Butler",
"Marketing Designer",
"San Francisco",
47,
"2009/12/09",
"$85,675"
],
[
"Howard Hatfield",
"Office Manager",
"San Francisco",
51,
"2008/12/16",
"$164,500"
],
[
"Hope Fuentes",
"Secretary",
"San Francisco",
41,
"2010/02/12",
"$109,850"
],
[
"Vivian Harrell",
"Financial Controller",
"San Francisco",
62,
"2009/02/14",
"$452,500"
],
[
"Timothy Mooney",
"Office Manager",
"London",
37,
"2008/12/11",
"$136,200"
],
[
"Jackson Bradshaw",
"Director",
"New York",
65,
"2008/09/26",
"$645,750"
],
[
"Olivia Liang",
"Support Engineer",
"Singapore",
64,
"2011/02/03",
"$234,500"
]
]
Failing JSON Data (Demo):
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
Returns
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
The demo returns contents from a PHP file.
header("HTTP/1.1 200 OK");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
Any suggestions would be very appreciated.
php json datatables
1
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to pass valid JSON to dataTables but any result that uses curly braces in the array is not accepted.
Working JSON Data[demo]:
"data":[
[
"Rhona Davidson",
"Integration Specialist",
"Tokyo",
55,
"2010/10/14",
"$327,900"
],
[
"Colleen Hurst",
"Javascript Developer",
"San Francisco",
39,
"2009/09/15",
"$205,500"
],
[
"Sonya Frost",
"Software Engineer",
"Edinburgh",
23,
"2008/12/13",
"$103,600"
],
[
"Jena Gaines",
"Office Manager",
"London",
30,
"2008/12/19",
"$90,560"
],
[
"Quinn Flynn",
"Support Lead",
"Edinburgh",
22,
"2013/03/03",
"$342,000"
],
[
"Charde Marshall",
"Regional Director",
"San Francisco",
36,
"2008/10/16",
"$470,600"
],
[
"Haley Kennedy",
"Senior Marketing Designer",
"London",
43,
"2012/12/18",
"$313,500"
],
[
"Jenette Caldwell",
"Development Lead",
"New York",
30,
"2011/09/03",
"$345,000"
],
[
"Yuri Berry",
"Chief Marketing Officer (CMO)",
"New York",
40,
"2009/06/25",
"$675,000"
],
[
"Caesar Vance",
"Pre-Sales Support",
"New York",
21,
"2011/12/12",
"$106,450"
],
[
"Doris Wilder",
"Sales Assistant",
"Sidney",
23,
"2010/09/20",
"$85,600"
],
[
"Angelica Ramos",
"Chief Executive Officer (CEO)",
"London",
47,
"2009/10/09",
"$1,200,000"
],
[
"Gavin Joyce",
"Developer",
"Edinburgh",
42,
"2010/12/22",
"$92,575"
],
[
"Jennifer Chang",
"Regional Director",
"Singapore",
28,
"2010/11/14",
"$357,650"
],
[
"Brenden Wagner",
"Software Engineer",
"San Francisco",
28,
"2011/06/07",
"$206,850"
],
[
"Fiona Green",
"Chief Operating Officer (COO)",
"San Francisco",
48,
"2010/03/11",
"$850,000"
],
[
"Shou Itou",
"Regional Marketing",
"Tokyo",
20,
"2011/08/14",
"$163,000"
],
[
"Michelle House",
"Integration Specialist",
"Sidney",
37,
"2011/06/02",
"$95,400"
],
[
"Suki Burks",
"Developer",
"London",
53,
"2009/10/22",
"$114,500"
],
[
"Prescott Bartlett",
"Technical Author",
"London",
27,
"2011/05/07",
"$145,000"
],
[
"Gavin Cortez",
"Team Leader",
"San Francisco",
22,
"2008/10/26",
"$235,500"
],
[
"Martena Mccray",
"Post-Sales support",
"Edinburgh",
46,
"2011/03/09",
"$324,050"
],
[
"Unity Butler",
"Marketing Designer",
"San Francisco",
47,
"2009/12/09",
"$85,675"
],
[
"Howard Hatfield",
"Office Manager",
"San Francisco",
51,
"2008/12/16",
"$164,500"
],
[
"Hope Fuentes",
"Secretary",
"San Francisco",
41,
"2010/02/12",
"$109,850"
],
[
"Vivian Harrell",
"Financial Controller",
"San Francisco",
62,
"2009/02/14",
"$452,500"
],
[
"Timothy Mooney",
"Office Manager",
"London",
37,
"2008/12/11",
"$136,200"
],
[
"Jackson Bradshaw",
"Director",
"New York",
65,
"2008/09/26",
"$645,750"
],
[
"Olivia Liang",
"Support Engineer",
"Singapore",
64,
"2011/02/03",
"$234,500"
]
]
Failing JSON Data (Demo):
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
Returns
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
The demo returns contents from a PHP file.
header("HTTP/1.1 200 OK");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
Any suggestions would be very appreciated.
php json datatables
I'm trying to pass valid JSON to dataTables but any result that uses curly braces in the array is not accepted.
Working JSON Data[demo]:
"data":[
[
"Rhona Davidson",
"Integration Specialist",
"Tokyo",
55,
"2010/10/14",
"$327,900"
],
[
"Colleen Hurst",
"Javascript Developer",
"San Francisco",
39,
"2009/09/15",
"$205,500"
],
[
"Sonya Frost",
"Software Engineer",
"Edinburgh",
23,
"2008/12/13",
"$103,600"
],
[
"Jena Gaines",
"Office Manager",
"London",
30,
"2008/12/19",
"$90,560"
],
[
"Quinn Flynn",
"Support Lead",
"Edinburgh",
22,
"2013/03/03",
"$342,000"
],
[
"Charde Marshall",
"Regional Director",
"San Francisco",
36,
"2008/10/16",
"$470,600"
],
[
"Haley Kennedy",
"Senior Marketing Designer",
"London",
43,
"2012/12/18",
"$313,500"
],
[
"Jenette Caldwell",
"Development Lead",
"New York",
30,
"2011/09/03",
"$345,000"
],
[
"Yuri Berry",
"Chief Marketing Officer (CMO)",
"New York",
40,
"2009/06/25",
"$675,000"
],
[
"Caesar Vance",
"Pre-Sales Support",
"New York",
21,
"2011/12/12",
"$106,450"
],
[
"Doris Wilder",
"Sales Assistant",
"Sidney",
23,
"2010/09/20",
"$85,600"
],
[
"Angelica Ramos",
"Chief Executive Officer (CEO)",
"London",
47,
"2009/10/09",
"$1,200,000"
],
[
"Gavin Joyce",
"Developer",
"Edinburgh",
42,
"2010/12/22",
"$92,575"
],
[
"Jennifer Chang",
"Regional Director",
"Singapore",
28,
"2010/11/14",
"$357,650"
],
[
"Brenden Wagner",
"Software Engineer",
"San Francisco",
28,
"2011/06/07",
"$206,850"
],
[
"Fiona Green",
"Chief Operating Officer (COO)",
"San Francisco",
48,
"2010/03/11",
"$850,000"
],
[
"Shou Itou",
"Regional Marketing",
"Tokyo",
20,
"2011/08/14",
"$163,000"
],
[
"Michelle House",
"Integration Specialist",
"Sidney",
37,
"2011/06/02",
"$95,400"
],
[
"Suki Burks",
"Developer",
"London",
53,
"2009/10/22",
"$114,500"
],
[
"Prescott Bartlett",
"Technical Author",
"London",
27,
"2011/05/07",
"$145,000"
],
[
"Gavin Cortez",
"Team Leader",
"San Francisco",
22,
"2008/10/26",
"$235,500"
],
[
"Martena Mccray",
"Post-Sales support",
"Edinburgh",
46,
"2011/03/09",
"$324,050"
],
[
"Unity Butler",
"Marketing Designer",
"San Francisco",
47,
"2009/12/09",
"$85,675"
],
[
"Howard Hatfield",
"Office Manager",
"San Francisco",
51,
"2008/12/16",
"$164,500"
],
[
"Hope Fuentes",
"Secretary",
"San Francisco",
41,
"2010/02/12",
"$109,850"
],
[
"Vivian Harrell",
"Financial Controller",
"San Francisco",
62,
"2009/02/14",
"$452,500"
],
[
"Timothy Mooney",
"Office Manager",
"London",
37,
"2008/12/11",
"$136,200"
],
[
"Jackson Bradshaw",
"Director",
"New York",
65,
"2008/09/26",
"$645,750"
],
[
"Olivia Liang",
"Support Engineer",
"Singapore",
64,
"2011/02/03",
"$234,500"
]
]
Failing JSON Data (Demo):
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
Returns
"data":["id":"in_1DLk6ZLrfrJRnR7ZLFRmoZAp","amount-paid":15911]
The demo returns contents from a PHP file.
header("HTTP/1.1 200 OK");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
Any suggestions would be very appreciated.
php json datatables
php json datatables
edited Nov 11 at 7:07


gratien asimbahwe
1,0372922
1,0372922
asked Nov 10 at 19:30
Kiril Climson
1314
1314
1
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41
add a comment |
1
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41
1
1
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You can only have the format your after if you don't have label names for the fields...
$return_array = array(
$customer['id'], $customer['amount_paid']);
}
As soon as you include labels - this starts to mean that the data is an object and not an array.
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
add a comment |
up vote
0
down vote
I think the problem not is the content of Json , it's content-type of your echoPost.php
Datatable is validating the content-type of response. And it's must be application/json
to be valid
Try this code :
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242656%2fwhy-is-json-with-curly-braces-invalid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can only have the format your after if you don't have label names for the fields...
$return_array = array(
$customer['id'], $customer['amount_paid']);
}
As soon as you include labels - this starts to mean that the data is an object and not an array.
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
add a comment |
up vote
0
down vote
accepted
You can only have the format your after if you don't have label names for the fields...
$return_array = array(
$customer['id'], $customer['amount_paid']);
}
As soon as you include labels - this starts to mean that the data is an object and not an array.
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can only have the format your after if you don't have label names for the fields...
$return_array = array(
$customer['id'], $customer['amount_paid']);
}
As soon as you include labels - this starts to mean that the data is an object and not an array.
You can only have the format your after if you don't have label names for the fields...
$return_array = array(
$customer['id'], $customer['amount_paid']);
}
As soon as you include labels - this starts to mean that the data is an object and not an array.
answered Nov 10 at 19:42
Nigel Ren
24k61832
24k61832
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
add a comment |
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
I'm so thankful - I can't believe it was that simple. However, could you clarify why an associative array doesn't work in JSON? I can't find an example online (sorry!) about why prevents valid JSON encoding.
– Kiril Climson
Nov 10 at 20:55
add a comment |
up vote
0
down vote
I think the problem not is the content of Json , it's content-type of your echoPost.php
Datatable is validating the content-type of response. And it's must be application/json
to be valid
Try this code :
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
add a comment |
up vote
0
down vote
I think the problem not is the content of Json , it's content-type of your echoPost.php
Datatable is validating the content-type of response. And it's must be application/json
to be valid
Try this code :
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
add a comment |
up vote
0
down vote
up vote
0
down vote
I think the problem not is the content of Json , it's content-type of your echoPost.php
Datatable is validating the content-type of response. And it's must be application/json
to be valid
Try this code :
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
I think the problem not is the content of Json , it's content-type of your echoPost.php
Datatable is validating the content-type of response. And it's must be application/json
to be valid
Try this code :
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
foreach ($api_response['data'] as $customer)
$return_array = array(
'id' => $customer['id'], 'amount-paid' => $customer['amount_paid']);
$mainArray['data'] = $return_array;
echo json_encode($mainArray);
answered Nov 10 at 19:49


Zuko
1856
1856
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242656%2fwhy-is-json-with-curly-braces-invalid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
9jr,0WLCkJ3,f7 bjd5Mm,gBXYM7u9MYCdRM,7QT1FYY9e0W0A,Y,ptMCkYCpuqqYjK,3KPIZ h3tkENZC,ad3q8XbHwCaTZS70
1
It would help to include a segment of the JSON in the question as external links may not be available in the future.
– Nigel Ren
Nov 10 at 19:33
maybe the json is invalid. Try a json validatior like jsonformatter.curiousconcept.com
– Pommesloch
Nov 10 at 19:34
It's valid! @Pommesloch It's quite a mystery. But if the file's inner curly braces are changed to square it remains valid on the jsonformatter.com & gets accepted. I can't figure out why ha!
– Kiril Climson
Nov 10 at 19:41