Json encoding

hello i believe i have a json encoding problem, im trying to encode a map into json and then consume with fullcalendar.io
i understand this may beyond support but any help will be appreciated.

fullcalendar.io can get from a route, which should contain json and then dynamically place it i thunk the issue is my keys are quoted, i can see the resp in chrome under network and the keys are quoted how do i unquote?
heres the code

---- encoder located at /api/calendar

def render("booked.json", _params ) do

##fetchbooked jobs from db
map = %{id: 1, allDay: false, start: "2017-05-18", end: "2017-05-18", title: "Room A" }
  to_string Poison.Encoder.encode(map,[])
    end

the response

 `{\"title\":\"Room A\",\"start\":\"2017-05-18\",\"id\":1,\"end\":\"2017-05-18\",\"allDay\":false}"

fullcalendar js thats not working

 $('#calendar').fullCalendar({

        events: {
            url: '/api/calendar',
            cache: true
        }


    })     

but it works with

$('#calendar').fullCalendar({

        events: [
            {
                id: '1',

                title: 'Meeting',
                start: '2017-05-14'
            }
        ]
    })


});
1 Like

First thing I notice is that your poison-encoded json has an id field with an integer value. In your working js example, id is a string.

changed to a string and still not working

OK. Are you setting your response type to application/json? This looks like a en/decoding problem, but when json is encoded as a string quoted key names are normal.

yes i am i can see the response in chrome devtools as a json it looks like “[{“title”:“Room A”,“start”:“2017-05-18”,“id”:“1”}]” also tried “{“title”:“Room A”,“start”:“2017-05-18”,“id”:“1”}”

It looks like it might be encoded twice. Try without the:

to_string Poison.Encoder.encode(map, [])

Just return the map as the view might be re-encoding the output. Just a thought.

2 Likes