0

I have an index.js file that is returning the body of an Eloqua REST obj using this code:

I have tried to use JSON.stringify and this prettyJOSNStringify

var request = require('request'); 
var prettyJSONStringify = require('pretty-json-stringify');

 request(  
     {  
        url : "https://secure.p03.eloqua.com/api/rest/2.0/assets/form/XXX",  
        headers : { "Authorization" : authenticationHeader }  
    },  
    function (error, response, body) {  
        console.log(prettyJSONStringify(body));  
    }  
);

but the response in the console is just a huge blob of JSON, how do I clean this up?

{\"type\":\"Form\",\"currentStatus\":\"Draft\",\"id\":\"912\",\"createdAt\":\"1544810248\",\"createdBy\":\"35\",\"depth\":\"complete\",\"folderId\":\"5487\",\"name\":\"Let's Connect Web Form 3.0 - Vertical\",\"permissions\":[\"Retrieve\",\"Delete\",\"Update\"],\"updatedAt\":\"1545074293\",\"updatedBy\":\"35\",\"customCSS\":\" \/* RESET *\/.elq-form * { margin: 0; padding: 0;}.elq-form input,textarea {\u0009-webkit-box-sizing:content-box;\u0009-moz-box-sizing:content-box;\u0009box-sizing:content-box;}.elq-form input[type=text],.elq-form textarea,.elq-form select[multiple=multiple] {\u0009border: 1px solid #A6A6A6;} .elq-form button,input[type=reset],input[type=button],input[type=submit],input[type=checkbox],input[type=radio],select {\u0009-webkit-box-sizing:border-box;\u0009-moz-box-sizing:border-box;\u0009box-sizing:border-box;}\/* GENERIC *\/.elq-form input {\

RobC
  • 22,977
  • 20
  • 73
  • 80
Alpdog14
  • 129
  • 2
  • 14
  • Can you clarify what you mean by _"cleaner"_... Do you mean omit the escaping, (i.e. ``\``) before the double quotes, and pretty print/indent the output. Or something else? – RobC Jan 03 '19 at 14:00
  • So yes kinda, I wanted it to do more of nested type look in my console, so that would be escaping the slashes but then but then nesting the elements in groups where appropriate. – Alpdog14 Jan 04 '19 at 19:26
  • @RobC did you have any other ideas on how to escape the "\" and do like a nesting of elements in the console.log output – Alpdog14 Jan 16 '19 at 15:56
  • Have you tried adding the properties `json: true` to your `request` options object, i.e. in the first object you pass, the one which currently specifies `url` and `headers` ? Then do `console.log(JSON.stringify(body, null, 2))`, instead of your current `console.log(prettyJSONStringify(body));` – RobC Jan 16 '19 at 16:48

0 Answers0