Skip to content

JSON.stringify output is truncated. #192

Description

@sbstp

I was debugging some code using JSON.stringifyand it seems that some objects get truncated.
That's the code in question.

print(JSON.stringify(members, null, 2));

members actually has 3 items. I've checked the length property. However, the output only has one element.

[
  {
    "wrapper": "CPtr",
    "to": {
      "wrapper": "CStruct",
      "members": [
        {
          "wrapper": "CType",
          "name": "double",
          "base_type": "f64",
          "size": 8,
          "load_fun": "$ir_load_f64",
          "store_fun": "$ir_store_f64",
          "wrapper_fun": null
        },

      ],
      "name": "s{}",
      "size": 16
    },
    "base_type": "*",
    "name": "*s{}",
    "size": 8,
    "load_fun": "$ir_load_rawptr",
    "store_fun": "$ir_store_rawptr"
  },
  ,

]

If I print the 3 items manually, like below, it displays all of them.

for (var i = 0; i < members.length; i++) {
    print(JSON.stringify(members[i], null, 2));
}

Thinking it maybe was a print bug, I checked the length of the generated strings. They should be about the same, ± a few characters. There's a huge gap! Doesn't look like a bug with print.

print(names.length, members.length);
var x = 0;
for (var i = 0; i < members.length; i++) {
    x += JSON.stringify(members[i], null, 2).length;
}
var y = JSON.stringify(members, null, 2).length;
print(x, y);
// ~1400, ~500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions