Response data in postman has some additional characters

postman special characters in body
postman character encoding
postman filter response body
postman extract value from json response
postman parse json response
postman response
postman validate json response
postman response encoding

I am using postgresql and node to create a crud application. I am having trouble sending post requests to the server. I tried testing the response data on postman, but the json data has some additional characters.

I have tried inserting data directly in the application and it works. I also tried using x-www-form-urlencoded and it works. The problem arises when i try posting using raw in postman.

const express = require('express');
const app = express();
const pg = require("pg");
const bodyParser = require('body-parser');

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
    next();
});

app.use(bodyParser.urlencoded({ extended: true }));

app.use(bodyParser.json());

const connectionString = "postgres://postgres:dennis@localhost:5432/School";
const pool = new pg.Pool({
    connectionString: connectionString
});

// app.use(express.json());

app.get('/', (req, res, next) => {

    pool.connect((err, client, done) => {
        if (err) {
            console.log("not able to connect " + err);
            res.status(400).send(err);
        }
        client.query("select * from student where id= $1", [1], (err, result) => {
            done();
            if (err) {
                console.log(err);
                res.status(400).send(err);
            }
            res.status(200).send(result.rows);
        })
    })
})

app.get('/students', (req, res, next) => {
    pool.connect((err, client, done) => {
        if (err) {
            console.log('error while connecting ' + err)
            res.status(400).send(err);
        }
        client.query("select * from student", (err, result) => {
            done();
            if (err) {
                console.log(err)
                res.status(400).send(err)
            }
            res.status(200).send(result.rows)
        })
    })
})

app.post('/add', (req, res, next) => {
    pool.connect((err, client, done) => {
        if (err) {
            console.log(err)
            return res.status(400).send('could not connect ' + err);
        }

        client.query("insert into student (id, name, rollnumber) values($1, $2, $3)", [req.body.id, req.body.name, req.body.rollnumber], (err, result) => {
            done();
            if (err) {
                return console.log(err)
            }

            res.json({
                message: req.body
            })
        })
    })
})

app.listen(4000, () => {
    console.log('working');
})

This is what i get from the req.body in postman. The json data has some funny characters.

{
    "message": {
        "{\r\n        \"id\": \"1\",\r\n        \"name\": \"jjjj\",\r\n        \"rollnumber\": \"7788\"\r\n    }": ""
    }
}

This is what I expect to get {"id": "1", "name": "jjj", "rollnumber": "7788"}

Please change the conent-type of the request. Now you are sending it as text format but you need to send it as json format.

Building requests, When you send a request, Postman will display the response received from the API If you have a request you want to run, you will need to know the URL, method, You can use a variety of other methods to send data to your APIs, including the The next generation processor will encode characters depending on where� Postman will indicate any whitespace / potentially invalid characters in parts of your request that may not function as expected so that you can rectify your values. You will see characters highlighted in the request method, URL (including the path), parameters, headers (including your key names), and body.

Please check this code,

req.body is not a JSON string anymore. So you first need to stringify and parse it.

res.json({
        message: JSON.parse(JSON.stringify(req.body))
})

Character encoding issues in Postman (master issue) � Issue #4555 , Several request has been made in terms of encoding errors on get requests on Postman Postman in general is of course a open source tool, wher Of course a response could also mention "why do you even transfer that data in GET ? Issue with the new line encoding (%5Cn instead of %0A) #2497. POST Request in Postman. The post is an HTTP method like GET. We use this method when additional information needs to be sent to the server inside the body of the request. In general, when we submit a POST request, we expect to have some change on the server, such as updating, removing or inserting.

In postman while sending json request body choose application/json. you are using text now.

Response, new Response(options). Response holds data related to the request body. By default, it provides a nice wrapper for url-encoded, form-data, and raw types of request bodies. A property can have a distinctive and human-readable name. This is to be used to display the name charset, String. the normalized character set. Task 1 - Filtering JSON data in Postman using parameters¶ This task demonstrates how to filter on the policy named ansible1 and display only the id value. Just like any Rest client, Postman can send parameters to the server so that the output is a customized response or a subset of the JSON data.

Lab 3.2: Filtering JSON data in Postman, Task 1 - Filtering JSON data in Postman using parameters� so that the output is a customized response or a subset of the JSON data. the special characters $, & are not escaped, in the curl requests they had to be. More on this later. A data file containing the cURL commands. Inspect Responses. View the status code, response time, and response size. Postman's automatic language detection, link and syntax highlighting, search, and text formatting make it easy to inspect the response body.

Postman Cheat Sheet, Postman Cheat Sheet, Cheat sheet for Postman, Cheat sheet for Postman JavaScript Examples to set & get in Postman. For more information you can visit Response contains a string Convert XML body to JSON object. The maximum length for the response text is 100000 characters Steps to reproduce the problem: Hit an API that returns a large (over 100000 characters) response.

Submit requests through Postman, Postman has a lot of other functionality you can use. also allows you to easily see the request headers, response headers, URL parameters, and other data. POST Request using Postman. In the previous tutorials, we have learnt about how to send a GET Request and we also learnt about the Request Parameters.From our Rest basics we already know what an HTTP Request and HTTP Response is.If you have not read these two tutorials yet, please do that before proceeding.

Comments
  • kindly share the postman screenshot
  • ibb.co/ssG0hbv. Here is the link to the image
  • I think, you are sending data using JSON.stringify(). Please make sure to parse it.
  • undefined:1 [object Object] ^ SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at Query.client.query [as callback] (E:\nodepost\app.js:75:30) at Query.handleReadyForQuery (E:\nodepost\node_modules\pg\lib\query.js:125:10) at Connection.<anonymous> (E:\nodepost\node_modules\pg\lib\client.js:244:19) at Connection.emit (events.js:189:13)