Getting “System.Collections.Generic.List`1[System.String]” in CSV File export when data is okay on screen

If an object you export as CSV with Export-Csv or ConvertTo-Csv has property values that contain a collection (array) of values, these values are stringified via their .ToString() method, which results in an unhelpful representation, as in the case of your array-valued .IPV4Addresses property. To demonstrate this with the ConvertTo-Csv cmdlet (which works analogously to … Read more

JSON.stringify deep objects

I did what I initially feared I’ll have to do : I took Crockford’s code and modified it for my needs. Now it builds JSON but handles cycles too deep objects too long arrays exceptions (accessors that can’t legally be accessed) In case anybody needs it, I made a GitHub repository : JSON.prune on GitHub … Read more

Convert javascript object or array to json for ajax data

I’m not entirely sure but I think you are probably surprised at how arrays are serialized in JSON. Let’s isolate the problem. Consider following code: var display = Array(); display[0] = “none”; display[1] = “block”; display[2] = “none”; console.log( JSON.stringify(display) ); This will print: [“none”,”block”,”none”] This is how JSON actually serializes array. However what you … Read more

Stringify (convert to JSON) a JavaScript object with circular reference

Circular structure error occurs when you have a property of the object which is the object itself directly (a -> a) or indirectly (a -> b -> a). To avoid the error message, tell JSON.stringify what to do when it encounters a circular reference. For example, if you have a person pointing to another person … Read more

Serializing object that contains cyclic object value

Use the second parameter of stringify, the replacer function, to exclude already serialized objects: var seen = []; JSON.stringify(obj, function(key, val) { if (val != null && typeof val == “object”) { if (seen.indexOf(val) >= 0) { return; } seen.push(val); } return val; }); http://jsfiddle.net/mH6cJ/38/ As correctly pointed out in other comments, this code removes … Read more