• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Json header

dr pepper

Well-Known Member
Most Helpful Member
I have a Esp8266 server responding to a json request from a client.
I'm using server.send(200, "json", html)
Html is a string I use to build the response, but there are some array's that are very long, so it uses loads of memory.
I tried to use server.sendContent() to do the job stepping through the arrays in a for loop, server.sendContent doesnt send any header, just raw data, I'm having trouble finding out what kind of header to send for json so I can build my own response.
I tried to get the debugger (F12) that comes with firefox to show me, of course it doesnt, just starts from <html>.

dr pepper

Well-Known Member
Most Helpful Member
Just in case anyone bumps this and wants to do the same thing, I found a way to do it with firefox browser, other browsers are similar:

Load a json response page, mine is xx.xx.xx.xx/data.json (the x's are my page IP).
Press f12 to open the developer tool in the browser (or right click & select inspect).
Select 'network' & click to refresh the page.
Click on the json file you want to look at in the list.
Move the switch button to 'raw headers'.
Your now looking at the header that the device sending the json reply sent to your browser.

In my case:

HTTP/1.1 200 OK
Content-Type: json
Content-Length: 1761
Connection: close

Seems the bit I missed was where it sends the content length, I need to write a routine to work out how long the file is, I think it includes all the punctuation marks and the data, everything except the header itself.


Well-Known Member
Most Helpful Member
Can you write a routine that has a flag for calculateLength/send so the same code does both?

I'm using server.streamFile() to send a file and occasionally it'll fail to send the correct amount for no apparent reason. I'd like to do something similar to try to get an idea of what's going wrong.


dr pepper

Well-Known Member
Most Helpful Member
Kinda, theres a way you can make the client calculate the length, I'm reading up on that now.

I use stream too, its way quicker, bit I odnt think I've run into that.

Latest threads

EE World Online Articles