Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #75
Closed
Open
Issue created May 05, 2015 by Administrator@rootContributor

Add method to measure the JSON length

Created by: max929292

I am using POST requests to send data to a webserver. These requests only work if we add the content length in the request. I do not want to use a char conversion via printTo as then I need to define the size of the char array which I would like to keep dynamic. I am directly pushing the json to my EthernetClient however I do not know if there is a simple way to pull the content length from it.

Would be great if you could give me some pointers.

EthernetClient client;
JsonObject& root = jsonBuffer.createObject();
....

client.println("POST /datapoints HTTP/1.1");
client.println("Host:  xxx.xxx.xxx.xxx:3000");
client.println("User-Agent: Arduino/1.0");
client.println("Accept: application/json");
client.print("Content-Length: ");
client.println(root.length);    //How can i get length of json? root.length() is not available
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
root.printTo(client);
Assignee
Assign to
Time tracking