You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Sanjaya Amarasinghe <ma...@sanjaya.me> on 2014/11/14 11:02:40 UTC

Getting a proper JSON using an erlang list function

Hi,

Using an Erlang list function I do the following :

*Send(list_to_binary(io_lib:format("~p~n", [TheObj]))),*

A sample of what I get as the result is as follows :

----------------
{{[{<<"_id">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
  {<<"_rev">>,<<"3-c477c16c92cdfc94ea5c619c7363650e">>},
  {<<"attrib1">>,true},
  {<<"complexAttrib">>,
   {[{<<"attrib2">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
     {<<"attrib3">>,<<"abc123">>}
     }]}},
  {<<"attrib4">>,<<"qwertyuiop">>},
  {<<"attrib5">>,true}]}
}
----------------


I need the "TheObj" to get printed in the proper JSON format in the
result.  I tried with ejeson:decode() and didn't get any success..

Can somebody help me with this ?

Thank you.
Regards,
Sanjaya

Re: Getting a proper JSON using an erlang list function

Posted by Sanjaya Amarasinghe <ma...@sanjaya.me>.
Thanks a lot Alexander. That does the job.
I couldn't figure it out before, because I'm not much familiar with Erlang.

On Fri, Nov 14, 2014 at 3:37 PM, Alexander Shorin <kx...@gmail.com> wrote:

> Hi,
>
> Obliviously ejson:decode wouldn't handle list_to_binary output right
> since this isn't valid JSON. Have you tried to do
> Send(ejson:encode(TheObj)) instead?
> --
> ,,,^..^,,,
>
>
> On Fri, Nov 14, 2014 at 1:02 PM, Sanjaya Amarasinghe <ma...@sanjaya.me>
> wrote:
> > Hi,
> >
> > Using an Erlang list function I do the following :
> >
> > *Send(list_to_binary(io_lib:format("~p~n", [TheObj]))),*
> >
> > A sample of what I get as the result is as follows :
> >
> > ----------------
> > {{[{<<"_id">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
> >   {<<"_rev">>,<<"3-c477c16c92cdfc94ea5c619c7363650e">>},
> >   {<<"attrib1">>,true},
> >   {<<"complexAttrib">>,
> >    {[{<<"attrib2">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
> >      {<<"attrib3">>,<<"abc123">>}
> >      }]}},
> >   {<<"attrib4">>,<<"qwertyuiop">>},
> >   {<<"attrib5">>,true}]}
> > }
> > ----------------
> >
> >
> > I need the "TheObj" to get printed in the proper JSON format in the
> > result.  I tried with ejeson:decode() and didn't get any success..
> >
> > Can somebody help me with this ?
> >
> > Thank you.
> > Regards,
> > Sanjaya
>

Re: Getting a proper JSON using an erlang list function

Posted by Alexander Shorin <kx...@gmail.com>.
Hi,

Obliviously ejson:decode wouldn't handle list_to_binary output right
since this isn't valid JSON. Have you tried to do
Send(ejson:encode(TheObj)) instead?
--
,,,^..^,,,


On Fri, Nov 14, 2014 at 1:02 PM, Sanjaya Amarasinghe <ma...@sanjaya.me> wrote:
> Hi,
>
> Using an Erlang list function I do the following :
>
> *Send(list_to_binary(io_lib:format("~p~n", [TheObj]))),*
>
> A sample of what I get as the result is as follows :
>
> ----------------
> {{[{<<"_id">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
>   {<<"_rev">>,<<"3-c477c16c92cdfc94ea5c619c7363650e">>},
>   {<<"attrib1">>,true},
>   {<<"complexAttrib">>,
>    {[{<<"attrib2">>,<<"54cc5f3f6db028666fdcb4b75ca0712f">>},
>      {<<"attrib3">>,<<"abc123">>}
>      }]}},
>   {<<"attrib4">>,<<"qwertyuiop">>},
>   {<<"attrib5">>,true}]}
> }
> ----------------
>
>
> I need the "TheObj" to get printed in the proper JSON format in the
> result.  I tried with ejeson:decode() and didn't get any success..
>
> Can somebody help me with this ?
>
> Thank you.
> Regards,
> Sanjaya