Playing with JSON

#34 Playing with JSON
6/19/2016

Summary

Some neat tips and tricks for interacting with and parsing JSON responses from an API.
6
ruby api json 3:10 min

Summary


consolerequire 'net/http'
require 'json'

url = 'http://jsonplaceholder.typicode.com/posts/1'
uri = URI(url)
response = Net::HTTP.get(uri)
standard = JSON.parse(response)
symbol =  JSON.parse(response, symbolize_names: true)
struct = JSON.parse(response, object_class: OpenStruct)

symbol[:name] = 'kobaltz'
struct.name = 'kobaltz'
struct.marshal_dump

require 'httparty'
require 'json'
url = 'http://jsonplaceholder.typicode.com/posts/1'
response = HTTParty.get(url)

standard = JSON.parse(response.to_json)
struct = JSON.parse(response.to_json, object_class: OpenStruct)
symbol =  JSON.parse(response.to_json, symbolize_names: true)
struct.marshal_dump


10906059?v=3&s=64
achmiral said 3 months ago:

Could you make another video about how to implement the technique in this video in a rails apps?

Thank you,

Login to Comment