Phillippe.j.h
Phillippe.j.h

Reputation: 1

How to display a json object as plain text with no brackets

Here I am getting a column from a database as a javascript object. I am then trying to get the contents from the object as a string via stringify and am rendering it to my ejs page. The contents from the data base are in a json format {"con":. How to i get the contents from the column to display as plain text?

var table= require('../models/table');

router.get('/', function(req, res){
    table.where({ id:1 })
        .fetch({ columns: ['con'] })
        .then(function(model){
            str = JSON.stringify(model);
            res.render('page.ejs', { str });
        });
});     

Upvotes: 0

Views: 1855

Answers (1)

Dennis Tang
Dennis Tang

Reputation: 226

You can use regex to remove []{} characters: str.replace(/[\[\]\{\}]+/g, '').

You can continue to escape other characters such as quotes if that's what you're looking for.

Upvotes: 1

Related Questions