Hi All ,    I am getting the below output JSON structure when I consume a REST API . I am able to view the same in trace log when I call the REST Service microflow. Please can you tell me how to display the content part of the output json in my app. When I click a button - > it will call the REST service microflow and I want the content part of the output json alone to be displayed in the browser,   Below is the  output JSON structure : {     "choices": [         {             "content_filter_results": {                 "hate": {                     "filtered": false,                     "severity": "safe"                 },                 "self_harm": {                     "filtered": false,                     "severity": "safe"                 },                 "sexual": {                     "filtered": false,                     "severity": "safe"                 },                 "violence": {                     "filtered": false,                     "severity": "safe"                 }             },             "finish_reason": "length",             "index": 0,             "logprobs": null,             "message": {                 "content": "The provided code is written in VBA (Visual Basic for Applications), a programming language used for writing macros to automate tasks within Microsoft Office applications. The code consists of several functions and subroutines, which are meant to be used within an Excel environment. Let's break down the components:\n\n**1. Module Declaration:**\n\n```vba\nAttribute VB_Name = \"Module1\"\n```\nThis line is automatically generated by the VBA editor to define the name of the module where the code is stored.\n\n**2. BMI Calculation Function:**\n\n```vba\nFunction bmi(weight, height) As Double\n    bmi = weight / (height / 100) ^ 2\n    bmi = Format(bmi, \"0.00\")\nEnd Function\n```\nThis function calculates the Body Mass Index (BMI) given a weight in kilograms and height in centimeters, and returns it formatted to two decimal places.\n\n**3. BMI Classification Function:**\n\n```vba\nFunction BMIClassify(bmx)\n    Select Case bmx\n        Case 0 To 18.5\n            BMIClassify = \"Underweight\"\n        Case 18.5 To 25\n            BMIClassify = \"Normal Weight\"\n        Case 25 To 30\n            BMIClassify = \"Overweight\"\n        Case 30 To 100\n            BMIClassify = \"Obese\"\n        Case Else\n            BMIClassify = \"Unknown\"\n    End Select\nEnd Function\n```\nThis function classifies the BMI value `bmx` into categories such as underweight, normal weight, overweight, obese, or unknown. There are typos in the `Case` statements (\"Underwight\" should be \"Underweight\", and \"DBMIClassify\" should be \"BMIClassify\").\n\n**4. Filter to 1 Criteria Subroutine:**\n\n```vba\nSub FilterTo1Criteria(Age)\n    Dim flag As Boolean\n    flag = False\n    Dim iListRow As ListRow\n    Dim iCol As Range\n    For Each iListRow In ActiveSheet.ListObjects(\"AgeRangeTable\").ListRows\n        For Each iCol In iListRow.Range\n            If flag Is True Then\n                Return True\n            End If\n            'if Age between iCol.Value then set flag = true\n        Next iCol\n    Next iListRow\nEnd Sub\n```\nThis subroutine seems incomplete or contains errors. It is intended to filter data based on age criteria, but it doesn't include the logic to do so. Additionally, `Return True` is not valid in VBA; it should be `Exit Sub` if the intention is to exit the subroutine early.\n\n**5. Get Value on Age Function:**\n\n```vba\nFunction getValOnAge(Age) As Double\n    ' ... (code omitted for brevity)\nEnd Function\n```\nThis function is meant to retrieve a value from a table named \"AgeRangeTable\" based on the provided `Age`. The function checks if the age falls within a certain range specified in the table and returns the corresponding value.\n\n**6. Button Click Event Subroutine:**\n\n```vba\nSub Button10_Click()\n    Count = WorksheetFunction.CountIf(Range(\"E38:H69\"), \"Yes\")\n    Dim Age As String\n    Age = Range(\"E25\")\n    Dim bmi As String\n    bmi = Range(\"D35\")\n    amount = 1000\n    premiumAmount = amount + amount * (Age * 0.1) + amount * (bmi * 0.1) + amount * (Count * 0.1)\n    Cells(70, 9).Value = premiumAmount\nEnd Sub\n```\nThis subroutine is triggered when a button (presumably with the name \"Button10\") is clicked. It calculates the `premiumAmount",                 "role": "assistant"             }         }     ],     "created": 1711522955,     "id": "chatcmpl-97Hat7aA0a8KHxhdT6y8HiMgv2Qug",     "model": "gpt-4",     "object": "chat.completion",     "prompt_filter_results": [         {             "prompt_index": 0,             "content_filter_results": {                 "hate": {                     "filtered": false,                     "severity": "safe"                 },                 "self_harm": {                     "filtered": false,                     "severity": "safe"                 },                 "sexual": {                     "filtered": false,                     "severity": "safe"                 },                 "violence": {                     "filtered": false,                     "severity": "safe"                 }             }         }     ],     "system_fingerprint": "fp_2f57f81c11",     "usage": {         "completion_tokens": 800,         "prompt_tokens": 623,         "total_tokens": 1423     } }
3 answers

Hi Divya,


I understand your issue, I hope below images can help you to understand


Screenshot 2024-03-29 121957.png



only select the message object and content so that you can get only that elements to map the attribute.


What you need to need to do is

1) create a JSON Structure based on the string above

2) create an import mapping based on the JSON structure and select the attributes you need

3) use the result of your REST call in your microflow to either display the content in a pop up, or create an object with a content attribute in which you place the mapped value and show the object in a page.


I can recommend you look at the following learning path section where above steps are explained in more detail (including exercise) and everything will make sense. 


Hi Divya,


It is very simple. To convert JSON output to the mx Object in mendix, we have to use Import mapping.


In Import mapping, select schema source as JSON Structure and Create a new JSON Structure and give the output structure in JSON Structure snippet.


 Then in import mapping click Select Elements and select the elements you want from JSON structure in the schema structure, i.e., In your case it is Content.


Now click Map Automatically in the import mapping to map the attributes.


Now the final step, Create a microflow and Call REST Service activity in the microflow.

Then in the response tab of this activity, select response handling as Apply Import Mapping and select the Import mapping which we created.


Then add an activity to show the overview page of created entity from Import Mapping.


Hope it helps Divya.