Output values into a Json dictionary

I get the following values from a database:

1234 , first 1, 123 ,third

and I want to output them as a json dictionary to a file

"1234" => {"key1" => "first 1" "key2" => 123 "key3" => "third 1"}

i can do this with codec line and format, but still wil be missing the curly bracket that open and close the entire json file:

**{**
      "1234" => {"key1" => "first 1" "key2" => 123 "key3" => "third 1"}
      "5678" => {"key1" => "first 2" "key2" => 456 "key3" => "third 2"}
**}**

is there a way to do this