[erlang-questions] How to convert sql return data to json

Jesper Louis Andersen <>
Thu Aug 31 15:13:46 CEST 2017


The way Erlang systems handle JSON data is the following:

1. In Erlang, every value passed around is an "Erlang Term".
2. A subset of these terms are representable in JSON.
3. JSON encoders such as 'jiffy' or 'jsx' are able to take the valid subset
from 2 and convert it into a binary containing the equivalent JSON
representation.

Your problem can be solved by taking the data you obtain from MySQL and
then convert the data into a form which follows the valid JSON subset and
has the structure you want. Then call something like `jsx:encode(Data)` on
your `Data`.

Some background on 2 above: Erlang terms can contain tuples such as {ok,
37} or {error, not_connected}. These do not have a representation in JSON
(since it lacks the equivalent of a symbol/atom and tuples). So most JSON
encoders reject Erlang terms containing tuples as subterms. The details
depend on the encoder though.

I can't remember if MySQL is able to return a result set directly as JSON,
and if it were, you have to check that the driver you use can handle such a
result as well--I can't help you much in this case, unfortunately.

Hopefully this will get you started on a solution!

On Thu, Aug 31, 2017 at 2:32 PM Palanikumar Gopalakrishnan <
> wrote:

> I want to get data from mysql and convert them into json format. I tried
> with this
>
> module
> https://sourceforge.net/projects/erlmysql/files/latest/download?source=directory
>
>
> Previously i tried this modules,
> https://github.com/Eonblast/Emysql
>
> This module give support for json conversion. But It was not support for
> Transaction.
>
> So I need to convert Sql return data to Json format. Please guide me to
> solve this challenge
>
>
>
>
>
>
> --
>
> *Warm Regards,*
>
> *Palanikumar Gopalakrishnan *[image: ✌]
> *Developer*
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170831/52624c2f/attachment.html>


More information about the erlang-questions mailing list