0

I have created a table name 'drugs' in chicagoboss. Mnesia has been used. Schema of the table is:

id, generic_name, brand_name, description

One record of the table is:

{
    drugs,
    "drugs-3",
    "Generic name",
    ["Trade Name","AnotherTradeName"],
    "This is the description of the drug"
}

To print the data in json format the code I have used:

-module(appname_drug_controller, [Req]).
-compile(export_all).

get('GET',[])->
  ADrugs=boss_db:find("drugs-3"),
  {json, [{resposne,ADrugs}]}.

I supposed to get:

{
  "resposne": {
    "id": "drugs-3",
    "generic_name": "Generic name",
    "brand_name": [
      "Trade Name",
      "AnotherTradeName"
    ],
    "description": "This is the description of the drug"
  }
}

But I am getting:

{
  "resposne": {
    "id": "drugs-3",
    "generic_name": "Generic name",
    "brand_name": "Trade NameAnotherTradeName",
    "description": "This is the description of the drug"
  }
}

So instead of array brand_name is returned as a single line of string. How can I get the correct structure?

  • What's the database in which you store the records? – Greg Apr 06 '16 at 15:36
  • If the record is correct when you read it from the shell then it will be a bug in `boss_db` or in the JSON encoder used by it. I would propose that you try to debug, e.g. add additional logging to the code reading the table or converting it JSON, recompile, re-run, and see which application doesn't do that correctly. – Greg Apr 07 '16 at 08:06
  • bossDb actually returning the correct format problem is in the json encoder I guess. – user1915863 Apr 08 '16 at 01:45
  • You can maybe try to use a different encoder, mine is here: https://github.com/yoonka/yajler/blob/master/src/yajler.erl It uses a C library for decoding JSON but encoding is a simple Erlang routine, you just call `yajler:encode(Term).` passing your term to encode as Term. It's 100 lines long so should be easy for you to change if needed. – Greg Apr 08 '16 at 08:26

0 Answers0