Skip to content

Commit

Permalink
Merge pull request #143 from usdAG/feat/json-beautifier
Browse files Browse the repository at this point in the history
JSON Beautifier
  • Loading branch information
felixb1515 authored Jun 7, 2024
2 parents 94036bd + 38edfbc commit 013e59e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/de/usd/cstchef/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import de.usd.cstchef.operations.conditional.StringContains;
import de.usd.cstchef.operations.conditional.StringMatch;
import de.usd.cstchef.operations.dataformat.FromBase64;
import de.usd.cstchef.operations.dataformat.JsonBeautifier;
import de.usd.cstchef.operations.dataformat.FromHex;
import de.usd.cstchef.operations.dataformat.HtmlDecode;
import de.usd.cstchef.operations.dataformat.HtmlEncode;
Expand Down Expand Up @@ -321,7 +322,7 @@ public static Class<? extends Operation>[] getOperationsDev() {
TimestampOffset.class, TimestampToDateTime.class, ToBase64.class, ToHex.class, UnixTimestamp.class,
UrlDecode.class, UrlEncode.class,
Whirlpool.class, WriteFile.class, XmlFullSignature.class, XmlMultiSignature.class,
Xor.class, SoapMultiSignature.class, Luhn.class, Concatenate.class
Xor.class, SoapMultiSignature.class, Luhn.class, Concatenate.class, JsonBeautifier.class
};
}

Expand Down
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;
}
}
}

0 comments on commit 013e59e

Please sign in to comment.