-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from usdAG/feat/json-beautifier
JSON Beautifier
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/de/usd/cstchef/operations/dataformat/JsonBeautifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.usd.cstchef.operations.dataformat; | ||
|
||
import burp.api.montoya.core.ByteArray; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import de.usd.cstchef.Utils; | ||
import de.usd.cstchef.operations.Operation; | ||
import de.usd.cstchef.operations.OperationCategory; | ||
|
||
@Operation.OperationInfos(name = "JSON Beautifier", category = OperationCategory.DATAFORMAT, description = "Format JSON Data.") | ||
public class JsonBeautifier extends Operation { | ||
@Override | ||
protected ByteArray perform(ByteArray input, Utils.MessageType messageType) throws Exception { | ||
try { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); | ||
JsonNode jsonNode = objectMapper.readTree(input.toString()); | ||
return factory.createByteArray(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode)); | ||
} catch (Exception e2) { | ||
return input; | ||
} | ||
} | ||
} |