Fix invalid JSON creation by removing comments and trailing comma