Jump to content

json where key = website address


BigDaddyO
 Share

Go to solution Solved by Danp2,

Recommended Posts

I'm trying to build a script to auto-add websites into Edge IE Compatibility view but i'm stuck reading the Preferences json file where the key name is a website which includes periods and forward slashes.

I'm using Ward's json udf from 2018.12.29

I've added Yahoo into the IE Compatibility view list to use as my test, below is a very cut down version for testing  but the actual file should be in your @LocalAppDataDir & "\Microsoft\Edge\User Data\Default\Preferences" if you want to look at the monster

{
  "dual_engine",{
    "user_list_data_1",{
      "https://www.yahoo.com/",{
        "date_added","13308840098237395"
        "engine",2
        "visits_after_expiration",0
      }
    }
  }
}

 

This is my sample code where I try to read but I get stuck when it comes to the website. I've tried replacing the . in the website with \. but that didn't help. 

$sFileToRead = @ScriptDir & "\test.json"
ConsoleWrite("Attempting to open json file (" & $sFileToRead & ")" & @CRLF)
$sJson = FileRead($sFileToRead)
If @error Then
    ConsoleWrite("Failed to read the json file @error = " & @error & @CRLF)
    Exit
EndIf

$oJson = Json_Decode($sJson)    ;Load the JSON file data into a Scripting dictionary
If @error Then
    ConsoleWrite("Failed to Decode the json data @error = " & @error & @CRLF)
    Exit
EndIf

;Trying to pull the info directly step by step
$oDualEng = Json_Get($oJson, '.dual_engine')
If @error Then
    ConsoleWrite("Unable to find dual_engine" & @CRLF)
Else
    ConsoleWrite("dual_engine was found" & @CRLF)
EndIf

$oUserList1 = Json_Get($oDualEng, '.user_list_data_1')
If @error Then
    ConsoleWrite("Unable to find user_list_data_1" & @CRLF)
Else
    ConsoleWrite("user_list_data_1 was found" & @CRLF)
EndIf

$sSiteName = Json_Get($oUserList1, '."https://www.yahoo.com/"')
If @error Then
    ConsoleWrite("Unable to find https://www.yahoo.com/" & @CRLF)
Else
    ConsoleWrite("https://www.yahoo.com/ was found" & @CRLF)
EndIf

 

Anybody have any ideas?

Thanks,

Mike

Link to comment
Share on other sites

46 minutes ago, jitb said:

Probaly not what your looking for, StringRegExp($sJson ,'(?:")(http.+)(?:")',1)

thanks but not what I need.  I have to read a specific field under the website and update if there.  else I need to create the website key and all items under it.

Link to comment
Share on other sites

The issue is that if Edge is synchronised to the cloud, local data will be overwritten, I've had a number of issues with updating Edge, Teams preferences where settings are overwritten by cloud version.  Any reason why you can't use Enterprise Mode List Manager to create your IEMode.xml file and then just add registry key to enable it:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Edge
InternetExplorerIntegrationSiteList = file:///C:/Data/IEMode.xml or better yet have it loaded onto a local webserver

Link to comment
Share on other sites

The company security is set very tightly.  I can't install the List manager so I built the .xml by hand but it turns out that I can't modify anything under the 'HKCU\Software\Policies' section in the registry so I can't point Edge to that .xml...  I also can't open regedit so I've had to do all this blindly via regwrite and regread.

SO!  I'm back to trying to modify this Preferences json file.  any ideas on how to access a key with a website as the field name?

This is going to be part of a website regression test, so every time I run my test it's going to check that json file and if it doesn't have the site i'm going to be running my test against i'm going to add it.  if it does have it but the created data is > 30 days then i'm going to update it to the current day.

 

Thanks

Link to comment
Share on other sites

  • Solution

Not sure if this helps, but you can get a list of the websites using Json_ObjGetKeys --

$sJSON = '{' & _
'  "dual_engine",{' & _
'    "user_list_data_1",{' & _
'      "https://www.yahoo.com/",{' & _
'        "date_added","13308840098237395"' & _
'        "engine",2' & _
'        "visits_after_expiration",0' & _
'      }' & _
'    }' & _
'  }' & _
'}'

$oJson = Json_Decode($sJson)    ;Load the JSON file data into a Scripting dictionary
If @error Then
    ConsoleWrite("Failed to Decode the json data @error = " & @error & @CRLF)
    Exit
EndIf

;Trying to pull the info directly step by step
$oDualEng = Json_Get($oJson, '.dual_engine')
If @error Then
    ConsoleWrite("Unable to find dual_engine" & @CRLF)
Else
    ConsoleWrite("dual_engine was found" & @CRLF)
EndIf

$oUserList1 = Json_Get($oDualEng, '.user_list_data_1')
If @error Then
    ConsoleWrite("Unable to find user_list_data_1" & @CRLF)
Else
    ConsoleWrite("user_list_data_1 was found" & @CRLF)
EndIf

$aKeys = Json_ObjGetKeys($oUserList1)
_ArrayDisplay($aKeys)

 

Link to comment
Share on other sites

Thanks Danp2 that was just the piece I was missing.  Json_ObjGetKeys gave me the item# it was in.  I then used Json_ObjGetItems with the same position it was found.

$sFileToRead = @ScriptDir & "\test.json"
ConsoleWrite("Attempting to open json file (" & $sFileToRead & ")" & @CRLF)
$sJson = FileRead($sFileToRead)
If @error Then
    ConsoleWrite("Failed to read the json file @error = " & @error & @CRLF)
    Exit
EndIf

$oJson = Json_Decode($sJson)    ;Load the JSON file data into a Scripting dictionary
If @error Then
    ConsoleWrite("Failed to Decode the json data @error = " & @error & @CRLF)
    Exit
EndIf

;Trying to pull the info directly step by step
$oDualEng = Json_Get($oJson, '.dual_engine')
If @error Then
    ConsoleWrite("Unable to find dual_engine" & @CRLF)
Else
    ConsoleWrite("dual_engine was found" & @CRLF)
EndIf

$oUserList1 = Json_Get($oDualEng, '.user_list_data_1')
If @error Then
    ConsoleWrite("Unable to find user_list_data_1" & @CRLF)
Else
    ConsoleWrite("user_list_data_1 was found" & @CRLF)
EndIf


$aKeys = Json_ObjGetKeys($oUserList1)
For $k = 0 to UBound($aKeys)
    If $aKeys[$k] = "https://www.yahoo.com/" Then ExitLoop
Next

$aItems = Json_ObjGetItems($oUserList1)
$sAddedOn = Json_Get($aItems[$k], ".date_added")
ConsoleWrite("Site was added on " & $sAddedOn & @CRLF)

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...