rutvij pandya
rutvij pandya

Reputation: 1

How to conver JSON collection into Hash using Rails 3

I am having JSON collection fetched from MongoDB & I want to convert it into Hash.

How can I do so..?

Thanks in advance..

Upvotes: 0

Views: 653

Answers (1)

Matt Briggs
Matt Briggs

Reputation: 42218

How did you fetch it from mongo? the ruby mongo driver automatically gives you ruby hashes.

EDIT: To take the second question into account

In mongo, queries don't actually execute until you call something that requires them to execute. Before you call to_json, you actually are still playing with a query object.

Instead of to_json, try just using to_a to get an array of hashes back.

Upvotes: 2

Related Questions