Add support for JSON.stringify to ComponentData

I suppose this is a sort of regression corner-case. The workaround seems to be to add a `JSON.stringify`-friendly `toJSON` method to `ComponentData` that serializes its view of itself. See #1548

Is this the correct solution?
I just checked again by commenting out the first two loops and the test does indeed fail. It's really strange though, because the `in` operator test does not fail. Any insights?