Python Forum
Parsing JSON with backslashes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing JSON with backslashes
#1
I have a script where the users will need to edit some variables. I don't want them to mess the script up so decided I would make a config json file where they could just edit the json rather than edit the script.

I don't want the users to have to understand \\, I want them to fill it in the way you would normally type a file path or domain user account. The problem is I get a json.decoder.JSONDecodeError: Invalid \uXXXX escape: line 5 column 22 (char 243) error. I understand why this is, but is there a way I can make it easy for the user, and Python ignore the error. Once I have parsed the JSON I will sort out the paths so Python can understand them.

def read_json_config():
    with open('console_config.json') as json_data:
        json_config_file = json.load(json_data)
This is my JSON file.

{
"ClientID":"8477295f-405",
"ClientSecret":"10f35a425670847eb63d9b1954592d2b8305cd87e3",
"ReportName":"Unprotected_Machines_",
"ReportFilePath":"c:\users\accounts\desktop\reports\",
"ConsoleName":"UK PS",
"SearchDomain":"dc=domain,dc=co,dc=uk",
"SearchUser":"domain\dap.l",
"SearchUserPassword":"password",
"DomainController":"10.0.1.20"
}
Reply


Messages In This Thread
Parsing JSON with backslashes - by bazcurtis - Jan-24-2020, 04:45 PM
RE: Parsing JSON with backslashes - by micseydel - Jan-24-2020, 06:21 PM
RE: Parsing JSON with backslashes - by bazcurtis - Feb-08-2020, 01:13 PM
RE: Parsing JSON with backslashes - by snippsat - Jan-24-2020, 07:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Parsing large JSON josvink66 5 730 Jan-10-2024, 05:46 PM
Last Post: snippsat
  Very simple question about filenames and backslashes! garynewport 4 2,041 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Parsing JSON pyStund 4 3,101 Jul-31-2022, 02:02 PM
Last Post: pyStund
  Json Parsing sshree43 5 1,853 May-04-2022, 09:21 PM
Last Post: snippsat
  json api data parsing elvis 0 953 Apr-21-2022, 11:59 PM
Last Post: elvis
  string indices must be integers when parsing Json ilknurg 3 6,498 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
  Help Parsing JSON kfwydfo1x 5 4,687 Jan-26-2021, 10:42 AM
Last Post: DeaD_EyE
  JSON parsing (nested) fakka 0 3,103 Nov-25-2019, 09:25 PM
Last Post: fakka
  f-strings and backslashes newbieAuggie2019 5 3,770 Oct-26-2019, 06:58 AM
Last Post: buran
  Parsing json - dictionary with in dictionary krish216 6 3,724 Jul-30-2019, 10:01 PM
Last Post: cvsae

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020