In LiveCode I have a stack connecting to a localhost MongoDB, the stack has a button with a mouseup handler and the function JSONToArray from MergJSON and two fields: "A" to receive the server answer "as is" and field B" to receive the decoded JSON.
This is the script of the button:
on mouseup
set the hideConsoleWindows to true
put shell("C:\\mongodb\bin\mongo.exe --eval" && quote & \
"printjson(db.test.findOne())" & quote) into pJSON
put pJSON into fld "a"
put JSONToArray(pJSON) into tArray
put tArray["a"] into fld "B"
end mouseup
The contents of fld "A" after mouseup is:
MongoDB shell version: 2.2.7
connecting to: test
{ "_id" : ObjectId("52e3f87c8da8b1efb07004c9"), "a" : 1 }
The script fails with the following LiveCode error:
executing at 8:58:32 PM
Type could not decode JSON: invalid token near 'MongoDB'
Object Completo
Line repeat for each line tKey in mergJSONDecode(pJSON,"tArray")
Hint could not decode JSON: invalid token near 'MongoDB'
If I change the script to:
on mouseup
put shell("C:\\mongodb\bin\mongo.exe --eval" && quote & "printjson(db.test.find())" & quote) into pJSON
put pJSON into fld "A"
end mouseup
Field "A" gets this:
MongoDB shell version: 2.2.7
connecting to: test
{
_"_mongo" : connection to 127.0.0.1,
_"_db" : test,
_"_collection" : test.test
_"_ns" : "test.test",
_"_query" : {
__
_},
_"_fields" : null,
_"_limit" : 0,
_"_skip" : 0,
_"_batchSize" : 0,
_"_options" : 0,
_"_cursor" : null,
_"_numReturned" : 0,
_"_special" : false,
_"help" : function () {
print("find() modifiers");
...
...
...
}
I am shortening the actual field "A" content, it has a lot of text.
Can you guide me please? What I am doing wrong? Why I am not getting a JSON. I checked { "_id" : ObjectId("52e3f87c8da8b1efb07004c9"), "a" : 1 }
using an online service finding that it is not a valid JSON.