term to json+erlang+chicago boss

130 views
Skip to first unread message

Laxmikant Gurnalkar

unread,
Oct 30, 2013, 6:07:09 AM10/30/13
to chica...@googlegroups.com
Hi Guys, 

I am trying to convert an erlang term to json. On google I had found some solutions but did not work for me.

This is the term that I have, In my controller: 

Properties = [
    {  type, "Land" },
    {  type_code: 1 },
    {  subtypes, [ { "1": "Field" }, { "2": "Other Field" }, { "3": "Grounds" }, { "4": "Forest" }, {  "5": "Other land" } ] }
].

I tried lots of modules like json2, erlang-json etc. but getting only one error. That's why I came on a conclusion I'm doing something wrong.

This is an error I'm facing each time:

1> json2:encode(Properties).    
** exception exit: {json_encode,{bad_term,{type,"Land"}}}
     in function  json2:encode/1 (json2.erl, line 92)



-Could you please tell me, anything wrong here.
-How to convert proplist to json in erlang?

I saw mochijson2 module to do that on google, but not found in erlang on my machine. Which might be part of mochiweb, I guess.
Is there any thing else available in erlang/ChicagBoss to do that?

Thank you.

Laxmikant Gurnalkar

kotedo

unread,
Oct 30, 2013, 10:01:39 AM10/30/13
to chica...@googlegroups.com
Hi,

The error is because there IS an error:
    {  type, "Land" },
should be
    {  type: "Land" },

—Kai

--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Slava P.

unread,
Oct 30, 2013, 10:08:34 AM10/30/13
to chica...@googlegroups.com
check https://github.com/klacke/yaws/blob/master/src/json2.erl for valid syntax and usage (there is a test/0 section)

> json2:encode(json2:obj_from_list([{type,"Land"},{type_code,1},{subtypes,json2:obj_from_list([{"1","Field"},{"2","Other Field"},{"3","Grounds"},{"4","Forest"},{"5","Other land"}])}])).
[123,
 [[["\"type\"",58,"\"Land\""],44,"\"type_code\"",58,"1"],
  44,"\"subtypes\"",58,
  [123,
   [[[[["\"1\"",58,"\"Field\""],
       44,"\"2\"",58,"\"Other Field\""],
      44,"\"3\"",58,"\"Grounds\""],
     44,"\"4\"",58,"\"Forest\""],
    44,"\"5\"",58,"\"Other land\""],
   125]],
 125]


8> jiffy:encode({[{type,<<"Land">>},{type_code,1},{subtypes,{[{<<"1">>,<<"Field">>},{<<"2">>,<<"OtherField">>},{<<"3">>,<<"Grounds">>},{<<"4">>,<<"Forest">>},{<<"5">>,<<"Otherland">>}]}}]}).
<<"{\"type\":\"Land\",\"type_code\":1,\"subtypes\":{\"1\":\"Field\",\"2\":\"OtherField\",\"3\":\"Grounds\",\"4\":\"Forest\",\"5\":\"Otherland\"}}">>




--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Sincerely, Slava P.

Laxmikant Gurnalkar

unread,
May 16, 2014, 8:09:16 AM5/16/14
to chica...@googlegroups.com
Hey Guys, Thanks for the quick replay and sorry for delay. Acually I had got the solution. So didn't reply on it.

Thanks for the reply

Jesse Gumm

unread,
May 16, 2014, 8:10:19 AM5/16/14
to chica...@googlegroups.com
Glad to hear it :)
> --
> You received this message because you are subscribed to the Google Groups
> "ChicagoBoss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to chicagoboss...@googlegroups.com.
> Visit this group at http://groups.google.com/group/chicagoboss.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chicagoboss/0192e50e-70da-4d87-8e96-02d54315b0da%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
Reply all
Reply to author
Forward
0 new messages