How do I use Jason instead of Poison?

I was very happy when I saw Jason to improved 30% the Json speed, but I didn’t find good document of Jason.

for example , my code was written with poison

def upload_drive_less_five(file, token) do
	    code = "Bearer #{token}"
	    HTTPoison.post!(
	    	"https://www.googleapis.com/upload/drive/v3/files?uploadType=media", # url
	    	{:file, file},  # body
	    	[{"Authorization", code}],  # headers
	    	[timeout: 50_000, recv_timeout: 50_000] # options
	    ).body
	    |> IO.inspect
 end

OR

def refresh_token (email) do
	refresh_token = HTTPoison.post!(
      	"https://www.googleapis.com/oauth2/v4/token", # url
	    {:form, # body
	    [
	    	{"client_id", "#{System.get_env("GOOGLE_CLIENT_ID")}"} ,
	    	{"client_secret", "#{System.get_env("GOOGLE_CLIENT_SECRET")}"} ,
	    	{"refresh_token", "#{get_pass_refresh_token(email)}"},
	    	{"grant_type", "refresh_token"}
	    ]
	    },
	    [{"Content-Type", "application/x-www-form-urlencoded"}] # headers
	    ).body
	|> Poison.decode

	{:ok, %{"access_token" => a_token}} = refresh_token

	update_token_after_refresh_token(email, a_token)
end

Now, What am I supposed to do in Jason?

1 Like

It seems like you’re confusing HTTPoison the HTTP client with Poison the json parsing/encoding package.

So |> Poison.decode would be |> Jason.decode in your second example, but that’s all that would change in your examples.

4 Likes