How to convert json object to query string in node js

You can convert the json object to query string in node js using stringify method. You have to just pass the object value to stringify method on querystring module it will convert the json object to query string node js.

Answers 1
  • Convert json object to query string in node js

    querystring = require('querystring');  
    const qs1=querystring.stringify({name:'samar',company:'w3codegenerator.com'});  
    console.log(qs1); 
    
    0

    Output:

    name=samar&company=w3codegenerator.com

    This code snippet will help you to convert the json object ({name:'samar',company:'w3codegenerator.com'}) to query string format (name=samar&company=w3codegenerator.com).

  • Back to code snippet queries related nodejs