Jump to content
JIMSMITH

A few questions about searching and updating JSON Data

Recommended Posts

Given the JSON object below.  I want to update the value of a JSON Pair.  Here are a few questions - 1) Is there a fast way to find the JSON details for fiddler@office365.com.  Do I have to loop through the each of the 4 entries. and check the value.  2) I want to update the new_token value from "rice" to "beans".  3) How do I add a new pair after "current_token". - This is last because I can probably figure #3 it out for myself.  Help is much appreciaded in advance.

 

{
    "SPWORKDATA": {
        "DB_PARAMS": {
        "DriverID":"Oracle",
                "Port":"9060",
                "Monitorby":"",
            "MetaDefSchema":"False"    },
    "MAILCONFIGS": [
        {"sole.heel@apple.com": {
         "clickid": "307663883943-8",
         "social": "weeklyreader",
         "account": "rick.flair@gmail.com",
         "new_token":"",
         "current_token":"1//0f1U7S6-TZ-_r6RtWc"
          }      
        },
        {"timmona@office365.com": {
         "clickid": "client_data2",
         "secret": "appsecret",
         "social": "timmon.ray@office365.com",
         "new_token":"scacral",
         "current_token":"refreshtoken"
          }
        },
        {"bruce@office365.com": {
         "clickid": "client_data2",
         "secret": "appsecret",
         "social": "bruce.richards@office365.com",
         "new_token":"soapl",
         "current_token":"refreen"
          }
        },

    {"fiddler@office365.com": {
         "clickid": "client_d89",
         "secret": "appsoul",
         "social": "karen.richards@office365.com",
         "new_token":"rice",
         "current_token":"old"
          }
        }

          ],
        "MEDIASERVER": {
            "Server": "192.162.2.185"
        },
        "MSGSERVER": {
            "Server": "127.0.0.1",
            "Port":"55555"
        }
    }

Edited by JIMSMITH
Add commas per comment.

Share this post


Link to post

Apologies. There are supposed to be commas.  I have added.  Thanks.  I made manual changes to for illustration purposes and make my 1st mistake.

Share this post


Link to post

It is a shame your MAILCONFIGS contains an array of objects that just contain another object.

Normally, you would use JsonPath for that, but Delphi's JsonPath support is very limited.

See:

Quote: "These operators do not support special expressions, they only support actual values (object properties or array indexes)."

 

I am afraid you will have to find the MAILCONFIGS node, and then iterate through it via code.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×