How to get the JSON fields and values in the controller?

The client sends the following JSON:

 {"User": {"name": "Jhon", "nationality", "brazilian", "gender": "male"}}

How can I get the JSON and each field and value individually for use in the controller and ecto query?

Automatically translated.

Upvotes: 2

Views: 1005

Answers (2)

JFAP
JFAP

Reputation: 3727

use elixir poison: https://github.com/devinus/poison

Then use:

Poison.decode!(~s({"User": {"name": "Jhon", "nationality", "brazilian", "gender": "male"}}), as: %User{})

Upvotes: 1

KA01
KA01

Reputation: 4251

You should be able use conn.params like so:

conn.params["User"], conn.params["User"]["gender"], etc.

Upvotes: 0

Related Questions