Questions tagged [elixir-poison]

Poison is a JSON library for Elixir focusing on speed without sacrificing simplicity, completeness, or correctness. Poison uses extensive sub binary matching, a hand-rolled parser using several techniques that are known to benefit HiPE for native compilation, IO list encoding and single-pass decoding. Benchmarks put Poison's performance next to jiffy's. Use this tag in combination with the [elixir] tag.

Poison is a JSON library for Elixir focusing on speed without sacrificing simplicity, completeness, or correctness.

Poison uses extensive sub binary matching, a hand-rolled parser using several techniques that are known to benefit HiPE for native compilation, IO list encoding and single-pass decoding. Benchmarks put Poison's performance next to jiffy's.

Use this tag in combination with the tag.

63 questions
0
votes
1 answer

Float format when json serializing in elixir

Elixir uses scientific notation by default for floats greater then 1000. This causes an undesired side effect during json serialization. iex(5)> val = 1000.00 1.0e3 iex(11)> Poison.encode(val) {:ok, "1.0e3"} The output I would like is iex(11)>…
noscreenname
  • 3,314
  • 22
  • 30
0
votes
1 answer

Convert string representation of an array of json objects to map Elixir

Here I have a payload coming to my controller action endpoint: %{ "mandrill_events" => "[{\"event\":\"send\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook…
Cyzanfar
  • 6,997
  • 9
  • 43
  • 81
0
votes
1 answer

Poison.EncodeError unable to encode value: {"has already been taken", []}

I am trying to return an invalid changeset. When doing conn |> put_status(422) |> put_view(Elemental.Auth.ErrorView) |> render("422.json-api", %{data: changeset}) OR conn |> put_status(422) |> put_view(Elemental.Auth.ErrorView) |> render(:errors,…
user2290820
  • 2,709
  • 5
  • 34
  • 62
0
votes
1 answer

Elixir: find by value prefix in nested JSON

I'm trying to find URLs in a nested JSON response and map them. My function so far looks like this: def list(env, id) do Service.get_document(env, id) |> Poison.decode! |> Enum.find(fn {_key, val} -> String.starts_with?(val, 'https')…
t56k
  • 6,769
  • 9
  • 52
  • 115
0
votes
1 answer

Retrieving response payload elements from XMLHttpRequest

I'm sending a JSON request (an applicative login but the kind of request doesn't matter) to a server with the following function: function login() { var payload = { "api_key" : "", "cmd" : "login", "params" : {} } …
mszmurlo
  • 1,250
  • 1
  • 13
  • 28
0
votes
0 answers

Append HTTP status to Poison encoded JSON before sending it out

Is there a way to put HTTP status in a particular struct before it's encoded by Poison? I guess the more general question would be can I access the conn at the level of my encoder's encode function? I am trying to build an API akin to what's…
hyde
  • 2,525
  • 4
  • 27
  • 49
0
votes
1 answer

Strange format of json response

I have a Phoenix app which is basically API. I have the following view: defmodule TattooBackend.Web.API.V1.AccountView do use TattooBackend.Web, :view alias TattooBackend.Repo def render("my_account.json", %{account: account}) do account…
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
0
votes
1 answer

How to add an item to list in cycle in Elixir/Phoenix

I'm studying Elixir/Phoenix and there is a task in front of me. I need to filter results from database in a cycle. Something like this: user = Repo.get_by(User, api_token: token) rooms = Repo.all(Room) result = [] if !Enum.empty?(rooms) do …
0
votes
1 answer

Unexpected token & in JSON when parsing object from string

I tried to parse data from elixir map converted to JSON using Poison.encode!(), in any case I got error: Unexpected token & in JSON at position 1 How to escape double quotes inside this string, to prevent adding ""e;"? Initial…
0
votes
1 answer

JSON encode GEO.Point from geo library as human readable form

I have this schema which has a Geo Geo.Point: defmodule Api.Shop do use Ecto.Schema import Ecto.Changeset import Api.Repo import Ecto.Query @derive {Poison.Encoder, only: [:name, :place_id, :geo_json, :distance]} schema "shops" do …
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
0
votes
1 answer

AJAX Post request error: "can't be blank", [validation: :required] When sending JSON object in POST body

I'm getting this error when a request hits my router at OPTIONS "/products" error 14:45:33.433 [error] #PID<0.339.0> running Api.Router terminated Server: 192.168.20.3:4000 (http) Request: OPTIONS /products ** (exit) an exception was raised: **…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
0
votes
1 answer

Ecto join query causing (Poison.EncodeError) unable to encode value

I have 3 tables: categories subcategories categorySubcategories 1 category has 0 to many subcategories. I have this function which gets all entries from categories table and only gets the entries of the subcategories table that belong to the…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
0
votes
1 answer

error trying to fetch from database and return result in http response

If I run Api.Category |> Api.Repo.all in iex I get this response in the terminal (basically I get two rows from the "categories" database table): iex(1)> Api.Category |> Api.Repo.all 16:21:55.775 [debug] QUERY OK source="categories" db=5.2ms…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
0
votes
1 answer

Serializing many to one relation with Phoenix

I'm looking for some kind of tutorial/example of serializing structs into json with Poison lib in Phoenix app. I've found such example: https://robots.thoughtbot.com/building-a-phoenix-json-api but it's not using Poison and it isn't covering structs…
michalSolarz
  • 485
  • 6
  • 18
0
votes
1 answer

Supervisor spawn processes which failover to other processes upon failure

I have two genserver implementations, both of which perform a lookup by making a http request and both return the same information, they use different providers in order to do so. I would like to figure out a way that I could have the first process…
Zac
  • 461
  • 5
  • 15