1

I have mentioned the code in which i have that query.I am requesting you to help me on the same lua or krakend config or Both. (Note Key is not exists)

LuaScript

  local docDetails = responseData:get("DocDetails")                                                                                                                                 
    -- docDetails:set("D_OffersAddOn", {}) -- Init OffersAddOn is an empty array.
    local discount = {
        ["D_Name"] = "Discount",
        ["D_Price"] = 0,
        ["D_Type"] = "value",
    }
    local D_OffersAddOn = docDetails:get("D_OffersAddOn") 
    -- D_OffersAddOn:set(0,discount)

We are getting

{
  "0": {
    "D_Name" : "Discount",
    "D_Price" : 0,
    "D_Type" : "value"
  }
}

insted of this I am exepecting

[
  {
    "D_Name" : "Discount",
    "D_Price" : 0,
    "D_Type" : "value"
  }
]

Line 1 --> getting DocDetails from response

Line 2 --> D_OffersAddOn key not exists in DocDetails. So I am creating an empty table

Line 3 --> I am creating the discount object(table)

Line 4 --> Selecting D_OffersAddOn array initially i created

Line 5 --> Now I am adding the discount object into an table as an array.

When I am doing below operation I am getting excepected as string but received as number.

-- D_OffersAddOn:set(0,discount)

If I am doing

docDetails:set("D_OffersAddOn", {discount})

then API returns below format.

{
  "0": {
    "D_Name" : "Discount",
    "D_Price" : 0,
    "D_Type": "value"
  }
}

But I am expecting the below format

{
  "DocDetails": {
    "D_OffersAddOn": [
      {
        "D_Name" : "Discount",
        "D_Price" : 0,
        "D_Type" : "value"
      }
    ]
  }
}
Vishal M
  • 11
  • 1

0 Answers0