简体   繁体   中英

Anypoint Studio Logger: pretty print JSON payload

Testing a POC and wondering what the quickest/simplest way to pretty print a JSON payload in the Anypoint Studio console. I'd rather not figure out how to use a Groovy component to accomplish this.

I've tried setting the application/json indent property to true as below, but it still prints the entire object on a single line (which is indented).

output application/json indent=true

Any lightweight solutions for quick POC work?

The console in Studio shows what it is being logged. If you are using DataWeave to create the JSON, as evidenced by the script you shared, then the default value for the indent writer property is true . So when logging it, the generated JSON will be pretty-printed by default.

Example:

    <ee:transform doc:name="Transform Message" >
        <ee:message >
            <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{ 
    a:"aaaa",
    b: {c:1, d:"dddd"},
    e: "ccc"
}]]></ee:set-payload>
        </ee:message>
    </ee:transform>
    <logger level="INFO" doc:name="Logger" message="Payload: #[payload]"/>

Output (omitting all the logging information for clarity):

Payload: {
  "a": "aaaa",
  "b": {
    "c": 1,
    "d": "dddd"
  },
  "e": "ccc"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM