How to save a API JSon data into outsystems entity
Question

Hi,

    Currently I am using an API which gives the data of the table(Match) the structure from the API is same as that of the entity's structure. The attribute 'ScoreBoard' in the table gets the json data from the API. I have tried the 'text' and 'binary' data type as the attribute's data type.


This is the sample data of the 'ScoreBoard' field

{
  "tieBreakPointTarget": "",
  "isTieBreak": false,
  "faultCount": 0,
  "setPointTarget": 8,
  "currentMatch": 2,
  "score": {
    "prim": {
      "1": 5,
      "2": 2
    },
    "sec": {
      "1": 8,
      "2": 1
    }
  },
  "serveId": 6288,
  "currentPoints": {
    "sec": 15,
    "prim": 40
  },
  "points": {
    "sec": {
      "BackhandWinner": 2,
      "BackhandForcedError": 1,
      "BackhandUnforcedError": 1,
      "ForehandUnforcedError": 3,
      "ServeAce": 15,
      "ForehandWinner": 15,
      "ForehandForcedError": 15
    },
    "prim": {
      "ForehandUnforcedError": 1,
      "ServeAce": 5,
      "ForehandWinner": 10,
      "ForehandForcedError": 1,
      "BackhandUnforcedError": 2,
      "BackhandForcedError": 12,
      "BackhandWinner": 8
    }
  },
  "currentAction": {
    "action": "BackhandWinner",
    "type": "prim"
  }
}


I have to save this json data into the ScoreBoard attribute and after saving to the entity, deserialise the data and take the object "Score" from JSON for display. 

Iam getting error while saving the JSON data into the 'scoreBoard' attribute of entity. How to save the json data into entity and get the json from db and display those contents after deserialising?  

Can any one give your help on this? Thanks in advance

Hi Kaarthick,

Wouldn't you think that showing us the actual error would help in helping you?

Hi Kaarthick,

The JSON can be saved as Text.  The only issue I can imagine is if the size of the JSON is too large for the ScoreBoard attribute.Try setting the ScoreBoard attribute to Text of length 2000.

What was the error message you experienced?

An issue to consider though, is that the JSON can differ in number of characters depending on the content, so you need to make sure the attribute is long enough for all possible cases.

Using binary would help ensure the JSON size does not cause an issue, but looking at this JSON, I don't think you need to go there.  If you do decide to use binary, you will need to convert to and from text, checkout the Binary Data API, and use BinaryDataToText, eg BinaryDataToText(TheData, "utf-8") and TextToBinaryData(TheBinary, "utf-8"). The Binary Data API is here https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/BinaryData_API#BinaryDataToText

It is also a good practice to split your table if you have an attribute holding large amounts of data.

I hope this helps.

Kind regards,

Stuart

Hi @Stuart Harris after a convert of API into Entity is that possible to create a role for that entity?If possible Kindly give some suggestion


Thanks,

Naveen Kumarasamy

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.