user40973: I have created an API in Ruby on Rails and it send the following JSON response:
{"sun_position":{"altitude":"32.46","azimuth":"223.93"}}

I'm able to successfully hit the API and store the response. But when I try to parse it and store data it gives me an error. I have used the Arduino JSON library.
The code for parsing the JSON is as follows:
bool parseSunPosData(char* content, SunPosData* sunPos) {
  StaticJsonBuffer<JSONBUFFER_SIZE> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(content);
  Serial.println("In parse fuc");
  Serial.println(content);
  Serial.println("==============");
  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  }

And the output on the serial monitor is as follows:

In parse fuc 38
{"sun_position":{"altitude":"32.46","azimuth":"223.93"}} 0
==============
JSON parsing failed! Disconnect

My guess is it can't parse the data due to the numbers 38 and zero printing... I don't know what that is and what it is.
PS: New to Arduino coding.

user37622: you have the HTTP chunked transfer encoding numbers in the content. 38 is the length of the body and it is on the first line of the HTTP body and 0 marks the end.
maybe try using ArduinoHttpClient library for HTTP

40973: <p>I have created an API in Ruby on Rails and it send the following JSON response:</p>

<pre><code>{"sun_position":{"altitude":"32.46","azimuth":"223.93"}}
</code></pre>

<p>I'm able to successfully hit the API and store the response. But when I try to parse it and store data it gives me an error. I have used the Arduino JSON library.</p>

<p>The code for parsing the JSON is as follows:</p>



<pre class="lang-cpp prettyprint-override"><code>bool parseSunPosData(char* content, SunPosData* sunPos) {
  StaticJsonBuffer&lt;JSONBUFFER_SIZE&gt; jsonBuffer;
  JsonObject&amp; root = jsonBuffer.parseObject(content);
  Serial.println("In parse fuc");
  Serial.println(content);
  Serial.println("==============");
  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  }
</code></pre>

<p>And the output on the serial monitor is as follows:</p>

<blockquote>
  <p>In parse fuc 38</p>
  
  <p>{"sun_position":{"altitude":"32.46","azimuth":"223.93"}} 0</p>
  
  <p>==============</p>
  
  <p>JSON parsing failed! Disconnect</p>
</blockquote>

<p>My guess is it can't parse the data due to the numbers 38 and zero printing... I don't know what that is and what it is.</p>

<p>PS: New to Arduino coding.</p>
 37622: <p>you have the <a href="https://en.wikipedia.org/wiki/Chunked_transfer_encoding" rel="nofollow noreferrer">HTTP chunked transfer encoding</a> numbers in the content. 38 is the length of the body and it is on the first line of the HTTP body and 0 marks the end.
maybe try using <a href="https://github.com/arduino-libraries/ArduinoHttpClient." rel="nofollow noreferrer">ArduinoHttpClient</a> library for HTTP</p>
