Creating request Object Json

Hi I am struggling with creating object json which I will send with affjax post request. What is the easiest way to generate object Json, either from record or in place, I have values in function I just need to create object out of it. :confused:

I saw that there is possiblity to generate SingletonObject but how do you make object with 2 fields ? and also it feels a bit dirty. Cannot I define type Profile = {name :: String, password :: String} and simply convert record to Object json ?

I find agronout generics but I have no idea how to use them. I am quite confused so any would help me a lot.

Yes, you can just define type Profile = { name :: String, password :: String } and convert that to a JSON value. You want the encodeJson function. All records are instances of the EncodeJson class as long as the types of their properties also are instances of EncodeJson.

^^ One example of the above:

That is exactly what I was looking for. I knew it would be easy to do this. :)) thank you guys.

1 Like