How to convert query string to json object in node js
Created at 01-Oct-2021 ,
By samar
How to convert query string to json object in node js
Through many examples, we will learn how to resolve the "How to convert query string to json object in node js".
You can convert query string to JSON object in node js app. You have to include querystring module and use parse method to get the object from query string URL.-
Convert query string to json object in node js
querystring = require('querystring'); const obj1=querystring.parse('name=samar&website=w3codegenerator'); console.log(obj1);
Output:
{ name: 'samar', website: 'w3codegenerator' }
Example code snippet
const querystring = require('querystring'); const url = "http://example.com/index.html?code=string&key=12&id=false"; const object = querystring.parse(url); console.log(object);
Output
{ 'http://example.com/index.html?code': 'string', key: '12', id: 'false' }
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Nodejs
- Get list of all installed packages in node project
- Npm ERR! missing script: start
- Axios Delete request with body and headers in ReactJS
- How to convert json object to query string in node js
- How to check if chart.js is installed ?
- How to check the version of installed package with NPM
- RESOLVE unable to resolve dependency tree