JSONObject from dot seperated strings

I am struggling with a specific problem, that I cannot think of correctly. The following is the problem

I have a map with key value like the following, i just used strings here

String key = "activate.message.success"
String value = "success"
String key1 = "activate.title"
String value1 = "Good Title"
String key2 = "activate.message.error"
String value2 = "error"
String key3 = "activate.message.short.poll"
String value3 = "This is short poll"

I need to build a json like the following

             "poll":"This is short poll"
       "title":"Good Title"

I could not think of a proper solution for this use case and struggling for 3 hours. I thought of using recursion, but i dont how exactly i could do. Please help with this. I am using java for this, I should use generic JSONObject to solve as there is not POJO mappings. So far I have just splitted the strings using separtor and stored in an another map like the following

public Map<String, Object> getJsonObjectFromKeyValueMap(Map<String, String> stringValueMap,
        Map<String, Object> stringObjectMap) {

    for (Entry entry : stringValueMap.entrySet()) {
        String[] keyValueArrayString = entry.getKey().toString().split("\\.");
        int sizeOfMap = keyValueArrayString.length;

        int i = 0;
        String concatString = "";
        for (String processKey : keyValueArrayString) {

            if (i < sizeOfMap - 1) {
                concatString += processKey + ".";
                stringObjectMap.put(concatString, (Object) new JSONObject());
            } else {
                concatString += processKey;
                stringObjectMap.put(concatString, entry.getValue());
                concatString = "";

    return stringObjectMap;

In my application, I use a JTable with a few resizable columns. At closing, I want the app to store the size of the columns displayed. My problem is that even if I manually resize the columns, the ...

I have a static matrixMult and static matrixAdd method and a static matrixDisplay(for print the result) and i wrote in Main function a example for test. My Goal: i want to multiply and add two matrix ...

I'm wondering if there was a way to get the sigar compiled binaries ie. libsigar-universal-macosx.dylib etc.. using maven. i know that i can just manually add it but I wish to automate the deployment

In my below FileWriter below, I am writing to a file called "employee.txt." It writes to the file but originally it was only appending to the file vs going into a new line each time. I since then ...