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

Palanikumar Gopalakrishnan <>
Fri Sep 1 14:36:59 CEST 2017


Hi guys,

               I tried with this modules
   https://github.com/talentdeficit/jsx,
   https://github.com/davisp/jiffy <https://github.com/davisp/jiffy>


But its need fieldname. My Sql driver returns data like below

















*for checking Sql result {{metadata,2,0,
{server_status,false,true,false,false,true,
false,false,false,false,false,false,false},
[{field_metadata,"def","zurik","erlang",
"erlang","name","name",33,135,253,
<<0,0>>,
0,[]},
{field_metadata,"def","zurik","erlang",
"erlang","id","id",63,11,3,
<<0,0>>,
0,[]}],                             []},
[["some",457],["some",457],["data2sosfasfme",42]]}*
*Please find my table structure below*
+----------------+------+
| name           | id   |
+----------------+------+
| some           |  457 |
| some           |  457 |
| data2sosfasfme |   42 |
+----------------+------+



Its that idea to get field name

On 31 August 2017 at 18:43, Jesper Louis Andersen <
> wrote:

> 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
>>
>


-- 

*Warm Regards,*

*Palanikumar Gopalakrishnan *[image: ✌]
*Developer*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170901/51b9c420/attachment-0001.html>


More information about the erlang-questions mailing list