0

I need help in creating a json sting in the following format.

[{"key": "hello world", "value": "hello world"}, {"key": "movies", "value": "movies"}, {"key": "ski", "value": "ski"}, {"key": "snowbord", "value": "snowbord"}]

my input data will be categories with following attributes.

:id, :name, :active

and I would like to use the :id as key and :name as value.

1 Answer 1

1
input_data.map { |d| { "key" => d.id, "value" => d.name } }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.