sajad torkamani

Encoding

You encode JSON when you convert a valid JSON object into a string. Here’s an example in Ruby:

require 'json'
person = { name: 'Bob', age: 30 }
JSON.generate(person)
# => "{\"name\":\"Bob\",\"age\":30}"

Decoding

You decode JSON when you convert a previously encoded JSON string into a JSON object. Here’s an example in Ruby:

json_string = "{\"name\":\"Bob\",\"age\":30}"
JSON.parse(json_string)
# => {"name"=>"Bob", "age"=>30}

Tagged: Misc