Person Data Extraction

PythonBeginner
Practice Now

Introduction

You have been provided with a JSON file containing information about a person, including their first name, last name, age, address, phone number, and email address.

Person Info

In this challenge, you will write a Python function to extract information about a person from a JSON file.

Your task is to write a Python function extract_person_info that reads the JSON file and returns a dictionary containing the person's first name, last name, zip code, and work phone number.

  • Sample JSON file: /home/labex/project/person_info_sample.json

Requirements

  1. The function should take the file ABSOLUTE path of the JSON file as a parameter.
  2. The function should return a dictionary with the following keys:
    • firstName: The person's first name.
    • lastName: The person's last name.
    • zipCode: The person's zip code.
    • workNumber: The person's work phone number.
  3. The function should use the json module to read the JSON file.
  4. The function should use the with statement to open the file, to ensure that the file is properly closed after reading.
  5. Your code should be well-documented and easy to understand.

Example

cd /home/labex/project
python person_info.py

Output:

{'firstName': 'John', 'lastName': 'Doe', 'zipCode': '12345', 'workNumber': '555-555-5678'}

Summary

Well done! You have now completed the Python challenge on the basics of using Python to process personal information.

✨ Check Solution and Practice