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

640
Views
Flask API failing to decode JSON data. Error: "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"

I'm setting up a simple rest api using flask and flask-restful. Right now all I'm trying to do is create a post request with some Json data, and then return it just to see if it works. I always get the same error "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"

Below is my code

from flask import Flask, jsonify, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)


class Tester(Resource):
   def get(self):
       return {'about': 'Hello World'}

   def post(self):
       data_json = request.get_json(force=True)
       return {'you sent': data_json}


api.add_resource(Tester, '/')

if __name__ == '__main__':
    app.run(debug=True)

The curl request I am making to test this is below, I've also tried making request using postman

curl -H "Content-Type: application/json" -X POST -d '{'username':"abc",'password':"abc"}' http://localhost:5000
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The curl request (payload) is incorrect. Use double quotes in the payload.

curl -H "Content-Type: application/json" -X POST -d '{"username":"abc","password":"abc"}' http://localhost:5000
over 4 years ago · Santiago Trujillo Report

0

You need to select raw -> JSON (application/json) in Postman like this:

enter image description here

When it comes to your cURL request, answer explains that windows's command line lacks support of strings with single quotes, so use:

curl -i -H "Content-Type: application/json" -X POST -d "{\"username\":\"abc\", \"password\":\"abc\"}" 127.0.0.1:5000

instead:

curl -H "Content-Type: application/json" -X POST -d '{'username':"abc",'password':"abc"}' http://localhost:5000

\ escapes " character.

over 4 years ago · Santiago Trujillo Report

0

You also need to have the Content-Length header enabled.

Without header

With header

over 4 years ago · Santiago Trujillo 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!