Python Forum
Parsing JSON with backslashes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing JSON with backslashes
#3
Two errors in this path because of escape characters.
>>> s = "c:\users\accounts\desktop\reports" # Removed last \
  File "<interactive input>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape

>>> # Fix 
>>> s = "c:\\users\\accounts\\desktop\\reports\\"
>>> s
'c:\\users\\accounts\\desktop\\reports\\'
>>> 
Do no use single \ in file paths.
import json
from pprint import pprint

def read_json_config():
    with open('c.json') as json_data:
        json_config_file = json.load(json_data)
        pprint(json_config_file)

read_json_config()
Output:
{'ClientID': '8477295f-405', 'ClientSecret': '10f35a425670847eb63d9b1954592d2b8305cd87e3', 'ConsoleName': 'UK PS', 'DomainController': '10.0.1.20', 'ReportFilePath': 'c:\\users\\accounts\\desktop\\reports', 'ReportName': 'Unprotected_Machines_', 'SearchDomain': 'dc=domain,dc=co,dc=uk', 'SearchUser': 'domain\\dap.l', 'SearchUserPassword': 'password'}
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 840 Jan-10-2024, 05:46 PM
Last Post: snippsat
  Very simple question about filenames and backslashes! garynewport 4 2,206 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Parsing JSON pyStund 4 3,313 Jul-31-2022, 02:02 PM
Last Post: pyStund
  Json Parsing sshree43 5 1,989 May-04-2022, 09:21 PM
Last Post: snippsat
  json api data parsing elvis 0 998 Apr-21-2022, 11:59 PM
Last Post: elvis
  string indices must be integers when parsing Json ilknurg 3 6,841 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
  Help Parsing JSON kfwydfo1x 5 4,826 Jan-26-2021, 10:42 AM
Last Post: DeaD_EyE
  JSON parsing (nested) fakka 0 3,156 Nov-25-2019, 09:25 PM
Last Post: fakka
  f-strings and backslashes newbieAuggie2019 5 3,874 Oct-26-2019, 06:58 AM
Last Post: buran
  Parsing json - dictionary with in dictionary krish216 6 3,845 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