Giter Club home page Giter Club logo

json-parse-challenge's Introduction

json-parse-challenge

Coding challenge that takes a file of records, parsing them and outputting as valid json according to a standard.

How to run

  • python run.py to process the input file and write out the ordered results as JSON. Output gets written to the output/result.out file.
  • python tests.py to run the unit tests.

Details

The input file will contain entries of personal information in multiple formats. These entries must be normalized into a standard JSON format.

Some sample lines might be:

Lastname, Firstname, (703)-742-0996, Blue, 10013
Firstname Lastname, Red, 11237, 703 955 0373
Firstname, Lastname, 10013, 646 111 0101, Green

The order and format of the lines may vary as above, in those 3 specific formats.

Some lines may be invalid, but should not interfere with processing. If a line is invalid, the line number is appeneded to an "errors" key at the end of the json file.

The "entries" list in the json file should be sorted in ascending alphabetical order by (last name, first name).

Solution

My solution was to validate the various entry parts with regular expressions, and then make acceptable formats using lists comprised of those regular expressions. For each line, it loops through the accepted formats and returns False if it finds a part that doesn't match up. At this point, the line number of the improperly formatted entry is added to the "errors" list of the class. If it makes it through without finding a mismatch, then the entry is deemed to have correct formatting, and the entry is added to the "entries" list of the class.

After all entries are processed, the entries are sorted, and output as JSON to the result.out file.

To do

  • Write more unit tests
  • Better handling of names that include middle names / initials

json-parse-challenge's People

Watchers

Timothy Shaw avatar

Forkers

behradtaher

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.