javascriptjsoncanjscanjs-model

Getting Straight Json from Can.Model


I use a c# 4.0 service to send json objects from a mongodb database to a website running canJS. I then show the json in a textarea on my page. The problem is that the json rendered in the text area has a weird duplication:

{
"_data": {
  "field1": 5,
  "field2": "Yitzhak",
},
"_cid": ".observe35",
"field1": 5,
"field2": "Yitzhak",
"_bindings": 1
}

This json is loaded using can.Model.findAll() then assigned to a field of a controller. Is there a way I can just print (and hold as a field) the basic Json without the duplication and can.Model additional information and no duplication?


Solution

  • On the off chance that anyone ever has this problem again:

    One way to fix it is at the point where you send it to the text area it add .attr() This cannot be added before because it causes a breaks jquery. eg.

    Excess printing:

    $(".textarea").text(JSON.stringify(jsonObject, undefined, 2));
    

    Correct:

    $(".textarea").text(JSON.stringify(jsonObject.attr(), undefined, 2));