From the course: Flask Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Parsing a JSON file for conflicting entries

Parsing a JSON file for conflicting entries

From the course: Flask Essential Training

Start my 1-month free trial

Parsing a JSON file for conflicting entries

- To prevent users from overwriting existing data inside of our urls.json, we need to do a check inside of our code to say, hey if this key already exists and has a url, don't update it. So, let's go ahead and move into our app dot pie and here, after we create our url's dictionary, let's check and see if we already have a urls.json file. So, for this, we're going to have to import some code to be able to read this from the file system. So, after our import json, we're going to do an import os.path and we'll use that here to say if os.path.exists and inside of this we need to check for the file. So, we're going to pass in a urls.json which is the name of our file. Then we'll do a colon to say if that is the case, we want to go ahead and open that file. So, similarly, like we see below, we're going to say with and we want to open. The inside of our parenthesis we want to specify the file name which is our urls.json…

Contents