Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
http: how to get json from batch response?

How do you get json from batch request?

I'm getting the following error if I console.log my fetch response.json():

Uncaught (in promise) SyntaxError: Unexpected number in JSON at position 3

If I dive into network sources to see the response (by the way it has status 200) in devTools I see the following line producing the error:

--batch_SuWHKrAohxj1o_r1qo6yzaAu-gfaqQ1p <-- producing error. Red lines underneath.
Content-Type: application/http
Content-ID: response-

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer

{
..........
..........
.........
}

My fetch() call has following headers:

  headers.append('Authorization', `Bearer ${token}`);
  headers.append('Host', 'www.googleapis.com');
  headers.append('Content-Type', 'multipart/mixed; boundary="deel_foo"');
  headers.append('Accept-Encoding', 'gzip');
  headers.append('Accept', 'application/json');
fetch(.....).then(response) => response.json())

each batch request inside body has Content-Type: application/json

EDIT:
I want the following response.

// stripped off the following:
--batch_K_aZ7aQTR91ApoeMUayvTEJhZBs6PW9n
Content-Type: application/http
Content-ID: response-

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer
// stripped off till here.
{   // I want this part, as it's valid JSON.
  "id": "17vegjeogjeogje44",
  "threadId": "17vjorgjerogjerogjer",
  "labelIds": [
    "CATEGORY_UPDATES",
    "INBOX"
  ],
  "snippet": "Don&#39;t miss this idea and many more. Stash what matters to you and inspire others. \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c \u200c",
  "payload": {
    "partId": "",
    "mimeType": "text/html",
    "filename": "",
    "headers": [
........
etc
........
etc........
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If someone else faces same issue:

I thought there was singular response with a body containing JSON. Technically there is a singular response but it's formatted as multiple responses.

Multipart responses actually contain multiple http responses each with an header and seperator --[foobar]. They aren't all concatenated inside a containing body and it needs to be manually tranformed into useable data by applying string/array methods or using a library.

There is no in-build solution for this equivalent to response=>response.json().

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!