Sample code for 30+ languages & platforms
Java

JSON Hex Encoding

See more JSON Examples

Let's say your JSON contains content that is hex encoded like this: \u05d1\u05d3\u05d9\u05e7

This example shows how to get the decoded string.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        String s = "{ \"example\": \"\\u05d1\\u05d3\\u05d9\\u05e7\" }";

        JsonObject json = new JsonObject();

        json.load(s);

        // When getting the member data, it is automatically decoded.
        System.out.println("member data: " + json.stringOf("example"));

        // Output:
        // member data: בדיק

        // When getting the full JSON, it remains encoded. This is expected and intentional.
        System.out.println("full JSON: " + json.emit());

        // Output:
        // full JSON: {"example":"\u05d1\u05d3\u05d9\u05e7"}

        // To get the full JSON without the encoding, you can decode manually.
        StringBuilder sb = new StringBuilder();
        json.emitSb(sb);
        // The hex encoding used by JSON is utf-8.
        sb.decode("json", "utf-8");

        System.out.println(sb.getAsString());

        // Output:
        // {"example":"בדיק"}
    }
}