0

I am getting json data from mongodb and display it using res.json(data). The result looks like following human readable format.

{
    "glossary": {
        "title": "example glossary"
                 }
}

Is there a way I can display this in raw Json without blank spaces and put them in one line? For example, {"glossary":{"title":"example".....

0

1 Answer 1

1

I find that very surprising (that it's rendering it that way). You might try res.send(JSON.stringify(data)). By default, JSON.stringify doesn't do any formatting.

Gratuitous JSON.stringify example:

var data = {
  "glossary": {
    "title": "example glossary"
  }
};
snippet.log(JSON.stringify(data));
<!-- Script provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.