user2901181
user2901181

Reputation: 343

More readbale way to test JSON parsing

I'm writing a program in Ruby that is parsing a fairly large JSON file. I'd like to be able to run a piece of Ruby code (in a testing environment) that parses this file, and see the information that has been extracted in a readable "pretty print" kind of way, for the sole purpose of testing.

So far I've just been testing things using irb in the terminal, but the output has no formatting whatsoever, so it's very difficult to figure out if things are working correctly. Is there a tool that makes JSON parsing a bit less painful?

Upvotes: 1

Views: 96

Answers (3)

Matt Weaver
Matt Weaver

Reputation: 1

You can copy and then paste a JSON object string into a code cleaner like http://www.dirtymarkup.com/ which will re-format the code into a more readable format.

Upvotes: 0

Nafaa Boutefer
Nafaa Boutefer

Reputation: 2359

awesome_print is a very convenient gem for this purpose. And about the REPL, I suggest to use pry instead of irb.

Upvotes: 1

zwippie
zwippie

Reputation: 15525

I suppose you are using json from the stdlib?

Anyhow, you can test your code with minitest or rspec. I would not test for readability of your output, but rather test that given an input X, you get expected output Y.

Upvotes: 0

Related Questions