ibmruntimes / yieldable-json

Asynchronous JSON parser and stringify APIs that make use of generator patterns
Other
145 stars 22 forks source link

Nested date objects are not get stringified properly #24

Closed mickeyjohn closed 3 years ago

mickeyjohn commented 4 years ago

Hi, I would like to report a bug in the case of date objects within sub arrays. My test codes are:

const yJson = require('yieldable-json');
var now = new Date();
var gData = { veh1: [{ a: 1, b: 2, at: now}, { a: 1, b: 2, at: now} ]}

yJson.stringifyAsync(gData, (err, res) => {
  if (err) return console.log(err);
  console.log(res); 
});

Result: {"veh1":[{"a":1,"b":2,"at":"2020-04-23T18:47:18.483Z"},[object Object]]} 

The expected result: {"veh1":[{"a":1,"b":2,"at":"2020-04-23T18:47:18.483Z"},{"a":1,"b":2,"at":"2020-04-23T18:47:18.483Z"}]}  which is the correct output when using JSON.stringify(gData);

If I changed gData to: var gData = { veh1: [{ a: 1, b: 2, at: new Date() }, { a: 1, b: 2, at: new Date() }] } It would work as expected. Does any one know why?

Thanks.

gireeshpunathil commented 4 years ago

@mickeyjohn - thanks for reporting this. This looks like a bug to me.

@harshithakp - can you pls have a look at this?

kbrownlees commented 4 years ago

Note that this actually has nothing to do with Date, it also occurs for an object:


  var now = { a: 1 };
  var gData = {
    veh1: [
      { a: 1, b: 2, at: now },
      { a: 1, b: 2, at: now }
    ]
  };

  yJson.stringifyAsync(gData, (err, res) => {
    if (err) return console.log(err);
    console.log(res);
  });

{"veh1":[{"a":1,"b":2,"at":{"a":1}},[object Object]]}

wanton7 commented 3 years ago

@HarshithaKP what is the current state of fixing this? Because without fixing this, this library won't be really usable in any project.

gireeshpunathil commented 3 years ago

@mickeyjohn , @wanton7 - the reported issue is fixed, and 2.0.1 is published. Let me know if you are able to use it and verify at your end!