# API Rest and JSon

**URL:** <https://forum.xojo.com/t/api-rest-and-json/88881>\
**Category:** General\
**Created:** [September 14, 2026, 1:37pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881 "2026-09-14T13:37:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nedi\_Freguglia](https://forum.xojo.com/user_avatar/forum.xojo.com/nedi_freguglia/32/337_2.png) [@Nedi\_Freguglia](https://forum.xojo.com/u/Nedi_Freguglia)\
**Post date:** [September 14, 2026, 1:37pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/1 "2026-09-14T13:37:46Z")

</div>

Hi everyone,

I need your help preparing to send invoices (headers and lines) via a REST API.

I need to construct a request body containing an array of headers (even if it consists of just a single element); each header is made up of a set of properties and an array of lines.

Since I don’t have much experience with JSON, I’m struggling to put this together.

Can anyone help me?

Thanks!!

Nedi

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [September 14, 2026, 4:01pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/2 "2026-09-14T16:01:23Z")

</div>

What have you tried? What issue(s) are you seeing? What’s the REST API look like (documentation)? Have you taken a look at the REST API example included with Xojo?

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [September 14, 2026, 4:35pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/3 "2026-09-14T16:35:36Z")

</div>

desktop app?

have a look at class URLConnection (there are fragments for send JSON too)

> **[URLConnection — Xojo documentation](https://documentation.xojo.com/api/networking/urlconnection.html)**

the http header becomes  
`Content-Type: application/json; charset=utf-8`  
and the count of bytes of the body  
`Content-Length: 1234`  
the end of a raw header are 2x CRLF  
followed by body data.

the json object is send as `.ToString` in the request body

> **[JSONItem — Xojo documentation](https://documentation.xojo.com/api/text/json/jsonitem.html#jsonitem)**
>
> Class

---

<div class="post-metadata">

**Author:** ![Nedi\_Freguglia](https://forum.xojo.com/user_avatar/forum.xojo.com/nedi_freguglia/32/337_2.png) [@Nedi\_Freguglia](https://forum.xojo.com/u/Nedi_Freguglia)\
**Post date:** [September 14, 2026, 6:01pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/4 "2026-09-14T18:01:18Z")

</div>

Thank you, guys!

I had to create a body with this structure:

Document

array of Document\_Header

value 1  
value 2  
value 3  
…  
array of Document\_Line  
value 1  
value 2  
value 3  
…

I don’t know how to manage the various JSonitem to do that.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [September 14, 2026, 6:44pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/5 "2026-09-14T18:44:17Z")

</div>

It works a lot like Dictionary, but can act like an array too.

I might do something like:

```json
Var Headers As New JSONItem("[]")
Headers.Add("value 1")
Headers.Add("value 2")
Headers.Add("value 3")

Var Lines As New JSONItem("[]")
Lines.Add("value 1")
Lines.Add("value 2")
Lines.Add("value 3")

Var Document As New JSONItem("{}")
Document.Value("Document_Header") = Headers
Document.Value("Document_Line") = Line

```

Two things to note here:

1. This is probably not correct for your implementation, but I’m working with the information I have.
2. Passing `"[]"` and `"{}"` is absolutely not necessary. I like to do it as a hint to my future self that the item should be an array vs a structure. It also prevents you from accidentally switching the JSONItem to the other mode before any content is added.

---

<div class="post-metadata">

**Author:** ![Nedi\_Freguglia](https://forum.xojo.com/user_avatar/forum.xojo.com/nedi_freguglia/32/337_2.png) [@Nedi\_Freguglia](https://forum.xojo.com/u/Nedi_Freguglia)\
**Post date:** [September 15, 2026, 6:49am UTC](https://forum.xojo.com/t/api-rest-and-json/88881/6 "2026-09-15T06:49:25Z")

</div>

Thank you, Tom. The correct structure of the body must be like this:

{  
“DocumentiT”: [  
{  
“key\_documento”: “…”,  
“num\_anno”: …,  
“des\_num\_doc”: “…”,  
“DocumentiR”: [  
{  
“key\_documento”: “…”,  
“prg\_riga”: …,  
“ind\_tiporiga”: “A”  
}  
]  
}  
]  
}

The problem is that I don’t know how to obtain it!

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [September 15, 2026, 7:01pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/7 "2026-09-15T19:01:17Z")

</div>

Here’s the “pretty” version, for anybody else reading:

```json
{
	"DocumentiT": [
		{
			"key_documento": "…",
			"num_anno": "…",
			"des_num_doc": "…",
			"DocumentiR": [
				{
					"key_documento": "…",
					"prg_riga": "…",
					"ind_tiporiga": "A"
				}
			]
		}
	]
}

```

I’ve given you the basic premise. You’re going to need to create a JSONItem struct with the keys `key_documento`, `prg_riga`, and `ind_tiporiga`. You then add that to a JSONItem array, and add _that_ array as the value for a `DocumentiR` key in a different struct. And so on. There’s definitely some nesting to do.

If you mean you don’t know how to get the JSON string to send over the socket, a quick look at the documentation would point you to the `ToString` method. Its default parameters will serve just fine for a REST API.

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [September 15, 2026, 8:15pm UTC](https://forum.xojo.com/t/api-rest-and-json/88881/8 "2026-09-15T20:15:35Z")

</div>

> JSONItem

to understand jsonitem create one and set a break point to see content in debug window.

explained json

> **[JSON](https://www.json.org/json-en.html)**

---

<div class="post-metadata">

**Author:** ![Gabriel\_Ludosanu](https://forum.xojo.com/user_avatar/forum.xojo.com/gabriel_ludosanu/32/20665_2.png) [@Gabriel\_Ludosanu](https://forum.xojo.com/u/Gabriel_Ludosanu)\
**Post date:** [September 17, 2026, 9:22am UTC](https://forum.xojo.com/t/api-rest-and-json/88881/9 "2026-09-17T09:22:15Z")

</div>

[Search Results for “json” – Xojo Programming Blog](https://blog.xojo.com/?s=json) 🙂

---

<div class="post-metadata">

**Author:** ![Nedi\_Freguglia](https://forum.xojo.com/user_avatar/forum.xojo.com/nedi_freguglia/32/337_2.png) [@Nedi\_Freguglia](https://forum.xojo.com/u/Nedi_Freguglia)\
**Post date:** [September 18, 2026, 7:19am UTC](https://forum.xojo.com/t/api-rest-and-json/88881/10 "2026-09-18T07:19:08Z")

</div>

Thank you all, guys!
