Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validate JSON file
#13
(Feb-27-2020, 08:41 AM)BellaMac Wrote: invalid json: 'charmap' codec can't decode byte 0x81 in position 145717: character maps to <undefined>

I also discovered that if I enter (python -m json.tool "C:\Engineering\test2\assetLink_tr-TR.json") on the CMD line, it works as what I am looking for. But I would still like to find out why the script does not work on UTF-8 JSON files.
Remember on Widows should and most in many cases most specify which encoding that should be used.
If not it will use charmap codec.
with open(fname, encoding='utf-8') as f:
The default encoding for Python 3 source code is utf-8,but read in and out OS may mess that up.
So as example both read and write do specify what encoding to use,
and that's always utf-8 if code starts in Python or as a first try in almost all cases.
s = 'Crème and Spicy jalapeño ☂'
with open('unicode.txt', 'w', encoding='utf-8') as f_out:
    f_out.write(s)

with open('unicode.txt', encoding='utf-8') as f:
    print(f.read())
Output:
Crème and Spicy jalapeño ☂
Reply


Messages In This Thread
Validate JSON file - by BellaMac - Feb-25-2020, 10:42 AM
RE: Validate JSON file - by johnb546 - Feb-25-2020, 10:53 AM
RE: Validate JSON file - by BellaMac - Feb-25-2020, 11:11 AM
RE: Validate JSON file - by DeaD_EyE - Feb-25-2020, 12:52 PM
RE: Validate JSON file - by BellaMac - Feb-25-2020, 01:44 PM
RE: Validate JSON file - by BellaMac - Feb-26-2020, 02:13 PM
RE: Validate JSON file - by DeaD_EyE - Feb-26-2020, 03:17 PM
RE: Validate JSON file - by BellaMac - Feb-26-2020, 05:46 PM
RE: Validate JSON file - by buran - Feb-26-2020, 05:49 PM
RE: Validate JSON file - by BellaMac - Feb-26-2020, 06:03 PM
RE: Validate JSON file - by buran - Feb-26-2020, 06:06 PM
RE: Validate JSON file - by BellaMac - Feb-27-2020, 08:41 AM
RE: Validate JSON file - by snippsat - Feb-27-2020, 03:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 239 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 771 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 2,553 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,151 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,552 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,286 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Create SQL connection function and validate mg24 1 960 Sep-30-2022, 07:45 PM
Last Post: deanhystad
Sad how to validate user input from database johnconar 3 1,936 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  Writing to json file ebolisa 1 1,016 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,505 Jul-16-2022, 02:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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