Generating JSON and posting it
- New
- How-to
- REST
-
Hannu Pikkarainen
- PowerBuilder
- Tuesday, 10 February 2026 07:44 AM UTC
Hi,
I need to generate JSON and post it to REST-interface and I have two problems with it:
Interface informs that JSON should begin with
{
"company_location_id": 0,
"currency_code": "string",
"delivery_method": 0,
"bank_code": "string",
"rf_reference": "string",
"agreed_due_date": "2026-02-03T08:38:56.924Z",
"cash_amount": 0,
"cash_amount2": 0,
"rows": [
{
"invoice_id": 0,
"batch_number": 0,
"delivery_customer_number": 0,
"delivery_date": "2026-02-03T08:38:56.924Z",
"order_number": 0,
"reference": "string",
"stock_id": 0,
"person_seller_id": 0,
"person_number": 0,
"sizes": [
{
"id": 0,
"row_id": 0,
"size": "string",
"ean": "string",
"amount": 0,
"dlvr_amount": 0,
"total_dlvr_amount": 0,
"sort_order": 0,
"in_stock": 0
}
],
If I start generating JSON with code
Long ll_RootObject, ll_ChildObject, ll_ChildArray
JsonGenerator lnv_JsonGenerator
string ls_Json
lnv_JsonGenerator = create JsonGenerator// Create an object root item
ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject, "object")
ll_RootObject = lnv_JsonGenerator.CreateJsonObject ()// Add an Object child item
ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject, "object")
lnv_JsonGenerator.AddItemString(ll_ChildObject, "company_location_id", "0")
lnv_JsonGenerator.AddItemDate(ll_ChildObject, "agreed_due_date", today())
lnv_JsonGenerator.AddItemString(ll_ChildObject, "delivery_customer_name", 'John Doe')
It results :
{"object":{"company_location_id":"0","agreed_due_date":"10-02-2026","delivery_customer_name":"John Doe"},"rows":[]}
PB demands that I create ItemObject with ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject, "object") and give name for it. Is there any way to create JSON without it or should I remove it with string functions afterward?
Secondly lnv_JsonGenerator.AddItemDate(ll_ChildObject, "agreed_due_date", today()) creates date formatted according to the Windows regional settings. Windows regional setting gives date in format 03.02.2026. Is there any way to convert this date value to format 2026-03-02 other than with string functions afterwards?
Third : Is there any other method generating the JSON preventing these problems?
And finally : Any advice how to set values to rows and sizes?
BR, Hannu
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.