Fixed marshalling to json

Added tests for correct marshalling