I have used JSON.stringify()
many times and I am aware of some issues such as (described in here):
- cycles
- too deep objects
- too long arrays
However, I am facing incorrect stringify operation on object which is like that:
After running JSON.stringify(obj) on console, I am getting that.
"[{"$$hashKey":"object:103",
"ProductCategories": [{"Id":2,"ShopProductCategoryName":"Drink","isSelected":true}
{"Id":3,"ShopProductCategoryName":"Food","isSelected":true}]
}]"
It only stringifies ProductCategories
and $$hashKey
which is totally unexpected.
Solving Attempts
If I create new object from obj
and stringify it, returns correct JSON.
var newObj = { // Creates new object with same properties.
AllProductCategories: obj.AllProductCategories,
Id: obj.Id,
LabelName: obj.LabelName,
Percentages: obj.Percentages,
ProductCategories: obj.ProductCategories
}
JSON.stringify(newObj); // Returns correct JSON.
I used the code to send object to web api compulsorily, but the way is not what I want, of course.
As I see,
- There is no cycles.
- It is not too deep. (only has depth 3)
Therefore, I cannot figure out what is wrong.