B
B
Bogdan2017-06-23 18:58:45
Ruby on Rails
Bogdan, 2017-06-23 18:58:45

Ruby ActiveRecord.as_json keys like Sybmol?

Hello. Could you tell? How, for example, to unload the table in JSON, so that the keys would be like Symbol.
Here it unloads where the row keys are:

value = Test.all.as_json  # [{"id"=>1 },{"id"=>2 }]
 # а надо [{:id=>1}, {:id=>2}]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Bordenyuk, 2017-06-23
@bogdan_uman

JSON.parse(Test.all.to_json, symbolize_names: true)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question