How to create json body to pass in HTTP Request(API) using each row data from my excel file and (I have to pass some fields as numbers and not string from excel)

Hi all,

Can someone help me creating json body from excel data and put in the HTTP Request(API) Body.

I have excel with 2000 rows, I have to read each row values and put in json body like below …

below example is for 2 rows

→ My goal is to achieve reading data from excel and generate json body for each row where “Part” and “Direction” field is always same and not from excel …

[

{

“Part”: “1”,
“Direction”: “N”,
“DEODE”: 45,
“DEFERENCE”: 0.2,
“OPERATDE”: “GY”,
“POSITION”: 1,
“TARI_ODE”: “0202”,
“GOODS_NAME”: “Goods Name1”,

},

{
“Part”: “1”,
“Direction”: “N”,
“DEODE”: 23,
“DEFERENCE”: 0.6,
“OPERATDE”: “UT”,
“POSITION”: 2,
“TARI_ODE”: “034302”,
“GOODS_NAME”: “GoHName1”,
}
]

→ Data that we need to read from excel is “DEODE”,“DEFERENCE”,“OPERATDE”, “POSITION”,“TARI_ODE”,“GOODS_NAME”,

→ Data in json body should be always number for fields DEODE,DEFERENCE,POSITION should be only number ..Not string (these values should not have double quotes in json body/payload)
→ I tried converting string to integer but value is getting changed when I have decimals, So I want to sent as it is value like number

Thank you,
Naresh

@Parvathy

Hi @Mandava_Naresh

Try this syntax:

jsonArray = New JArray(
    From row In dt.AsEnumerable()
    Select New JObject(
        New JProperty("Part", "1"),
        New JProperty("Direction", "N"),
        New JProperty("DEODE", Convert.ToDecimal(row("DEODE"))),
        New JProperty("DEFERENCE", Convert.ToDecimal(row("DEFERENCE"))),
        New JProperty("OPERATDE", row("OPERATDE").ToString()),
        New JProperty("POSITION", Convert.ToInt32(row("POSITION"))),
        New JProperty("TARI_ODE", row("TARI_ODE").ToString()),
        New JProperty("GOODS_NAME", row("GOODS_NAME").ToString())
    )
)

=> Use the below syntax to convert to jsonString
jsonString = jsonArray.ToString()

Hope it helps!!