-4

I have a String as below stored in datasets_detail column of table item_action_info :

[{
    "datasetAttributeId": 5,
    "nextUpdate": 1587546084,
    "lastSuccessfulRefreshTime": 1587546084,
    "refreshActionId": 2,
    "errorCode": 0,
    "isMFAInstanceRefreshRequired": false
}, {
    "datasetAttributeId": 6,
    "nextUpdate": 1587546084,
    "lastSuccessfulRefreshTime": 1587546084,
    "refreshActionId": 2,
    "errorCode": 0,
    "isMFAInstanceRefreshRequired": false
}, {
    "datasetAttributeId": 8,
    "nextUpdate": 1587546084,
    "lastSuccessfulRefreshTime": 1587546084,
    "refreshActionId": 2,
    "errorCode": 0,
    "isMFAInstanceRefreshRequired": false
}]

I want replace value for each occurrences of "lastSuccessfulRefreshTime". How to i do in Java? Below is sample piece of code. Please advice in completing the same.

String strJson =CommonUtils.clobStringConversion(resultSet.getClob("DATASETS_DETAILS"));

// complete the rest code here

Ramesh
  • 340
  • 1
  • 7
  • 21
rahul kumar
  • 43
  • 1
  • 6
  • This seems like a straightforward problem. Please explain what is causing you difficulties in doing this yourself, and illustrate it with your attempt at solving it. – Stephen C Jun 27 '18 at 08:10
  • String replace? https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence) – maio290 Jun 27 '18 at 08:12

1 Answers1

0

If you want to manipulate it as a JSON object, then you can do it via Google GSON.

String strJson =CommonUtils.clobStringConversion(resultSet.getClob("DATASETS_DETAILS"));

Gson gson = new Gson();
List<StringMap> parsedObject = new Gson().fromJson(strJson, List.class);

// Final String
String newReplacedString = gson.toJson(parsedObject.stream().map((item) -> {
    // Put your new value here
    item.put("lastSuccessfulRefreshTime", "Replaced Value");
    return item;
}).collect(Collectors.toList()));
deepansh2323
  • 261
  • 1
  • 8