Every valid string can be a valid key in JSON. So parentheses in key names are possible.
It is up to the application to interpret the content of the parentheses.
Answer from wizardofOz on Stack OverflowIm working with a 3rd party API and recieved a response of what seems like an object wrapped in a parentheses?
I really dont know how to parse this as when I try to .json() or JSON.parse() it it throws an error (Unexpected token u in JSON at position 0) I'm assuming due to the "useriata" that's wrapping the object.
Asking for help.
Clean up double brackets for JSON parse
How to ignore leading parenthesis in JSON?
php - Manipulate JSON node to have [] parentheses - Stack Overflow
string that contain parentheses to json? - javascript
You should use a callback parameter in the url you provided for accessing the data. Because the data interchange format is jsonp. Those parenthesis are probably added because the callback is being evaluated as an empty string.
See the example below with the url you provided.
https://getbible.net/json?passage=1samuel3:16&v=cus&callback=foo //foo is the callback name
It returns the data with the callback name foo.
foo({"book":[{"book_ref":"1 S","book_name":"1 Samuel","book_nr":"9","chapter_nr":"3","chapter":{"16":{"verse_nr":"16","verse":"\u4ee5 \u5229 \u547c \u5524 \u6492 \u6bcd \u8033 \u8bf4 \uff1a \u6211 \u513f \u6492 \u6bcd \u8033 \u554a \uff01 \u6492 \u6bcd \u8033 \u56de \u7b54 \u8bf4 \uff1a \u6211 \u5728 \u8fd9 \u91cc \uff01\r\n"}}}],"direction":"LTR","type":"verse","version":"cus"});
See the example below which shows how to access the data.
var url="https://getbible.net/json?passage=1samuel3:16&v=cus&";
var callbackname = "callback";
$.getJSON(url+'callback=' + callbackname, function(json){
//loop through data
$.each(json.book,function(i,dat){
document.write(dat.book_ref); //print the book reference "1 S"
});
});
I think here that PHP json_encode is "right", the value returned by the first link you posted is not valid JSON, but merely seems a fragment of javascript code for a variable assignment.
See in fact the JSON specification, which clearly states that a JSON object must start with { and end with }