Skip to content

JsonFieldPatternBuilder mask nested json field break json format #29

Description

@AKKID

Issue Report

When using the JsonFieldPatternBuilder to mask sensitive data within a nested JSON structure, the resulting output is not in a valid JSON format.

Sample code

public class EJMaskTest {
    static {
        EJMaskInitializer.addFilter(
                new BaseFilter(JsonFieldPatternBuilder.class, 4, "innerKey1")
        );
    }


    public static void main(String[] args) throws JsonProcessingException {
        String input = "{\"outer\":\"  {\\\"innerKey1\\\": \\\"191287127167167\\\",\\\"innerKey2\\\":\\\"testInnerInformation\\\"}\"}";
        String output = EJMask.mask(input);
        System.out.println(input);
        System.out.println(output);
    }
}

Below is the output

{"outer":"  {\"innerKey1\": \"191287127167167\",\"innerKey2\":\"testInnerInformation\"}"}
{"outer":"  {\"innerKey1\": \"1912-xxxx",\"innerKey2\":\"testInnerInformation\"}"}

Expected Behavior

The expected output should mask only the innerKey1 value from 191287127167167 to 1912-xxxx, while leaving all other content unchanged. The correct output should be:

{"outer":"  {\"innerKey1\": \"1912-xxxx\",\"innerKey2\":\"testInnerInformation\"}"}

Actual Behavior

The actual output is:

{"outer":"  {\"innerKey1\": \"1912-xxxx",\"innerKey2\":\"testInnerInformation\"}"}

There is a missing escape character (backslash) following 1912-xxxx, which results in an invalid JSON format.

Steps to Reproduce the Issue

  1. Use the code provided in the "Sample Code" section.
  2. Observe the output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions