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

126
Views
Node.JS spawning Python process gives error 'JSONDecodeError("Expecting value", s, err.value) from None'

I'm trying to spawn a python process (App.py) from a node.js file (index.js).

The script index.js spawns the python script App.py, and passes it an argument params (a json object). App.py then reads the uParams element parameter1 and sends the value as a message back to index.js.

However when I run the index.js script I get the error, JSONDecodeError("Expecting value", s, err.value) from None.

I tried to replace json.loads(sys.argv[1]) with sys.argv[1] but running it gives me the error TypeError: string indices must be integers.

Did I wrongly format the 'params' JSON object in index.js?

Could you please help me spot the problem?

Thanks in advance!

index.js:


const spawn = require("child_process").spawn;

let params = {
  "type":"numbers",
  "lang":"js",
  "uParams":[{
    "parameter1":1,
    "parameter2":2,
    "parameter3":3
    }]  
}

const pythonProcess = spawn('python',['./App.py', params]);

pythonProcess.stdout.on('data', (data)=>{
  console.log(data.toString());
});

App.py:


import sys, json

params = json.loads(sys.argv[1])

print(params['uParams'][0]['parameter1'])
sys.stdout.flush()

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to stringify your JSON object with JSON.stringify.

const pythonProcess = spawn('python',['./App.py', JSON.stringify(params)]);

Frankly I'm surprised spawn isn't complaining that it only accepts string arguments, but it must be calling toString on your object so you're just passing [object Object].

> ({foo:'bar'}).toString()
'[object Object]'
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!