Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex on json file
#1
I'm trying to match a regex expression to the value of Id in a json file. My goal is to iterate over a bunch of json files in a directory and replace the value of the Id key with the regex match. The regex works well by itself when i try it on regex101, however when I run it again the json files on my computer i get a
Error:
TypeError: expected string or bytes-like object
. Any and all help appreciated.

import json
import os
import re


rootdir = r'C:\\Users\\homersimpson\\jsondumps'

for files in os.scandir(rootdir):

        with open(files, "r") as file:
            json_data = json.load(file)
            extracted  = re.findall((r'.+?(?<=\$apples\$)'),json_data)
            print(something)
Reply


Messages In This Thread
regex on json file - by senaint - May-05-2020, 05:45 AM
RE: regex on json file - by bowlofred - May-05-2020, 06:17 AM
RE: regex on json file - by buran - May-05-2020, 07:57 AM
RE: regex on json file - by senaint - May-05-2020, 04:15 PM
RE: regex on json file - by buran - May-05-2020, 04:24 PM
RE: regex on json file - by senaint - May-05-2020, 07:54 PM
RE: regex on json file - by buran - May-05-2020, 08:18 PM
RE: regex on json file - by senaint - May-05-2020, 09:49 PM
RE: regex on json file - by bowlofred - May-05-2020, 11:22 PM
RE: regex on json file - by senaint - May-06-2020, 12:37 AM
RE: regex on json file - by bowlofred - May-06-2020, 03:58 AM
RE: regex on json file - by buran - May-06-2020, 03:15 AM
RE: regex on json file - by buran - May-06-2020, 04:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 326 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 828 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 2,645 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,265 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  search file by regex SamLiu 1 962 Feb-23-2023, 01:19 PM
Last Post: deanhystad
  Split pdf in pypdf based upon file regex standenman 1 2,192 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,877 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,339 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 1,061 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,585 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