in reply to need help in validating json

Have you looked at whether your code works for a single object instead of 20 objects?

As a simple example, I don't see where you output the closing ] for your array of objects.

If you're using from_json to validate your output, why don't you use to_json to create your JSON output? At least for testing and comparing the created data, this seems to me a much easier approach to creating correct data.