Skip to content

drastawi/json-flattener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongo JSON formatter

MongoDB takehome problem by Dominik Rastawicki.

This project contains a program that takes a JSON object as input and outputs a flattened version of the JSON object, with keys as the path to every terminal value in the JSON structure.

Getting Started

This project uses python 3.8.0.

To run the program:

python json_formatter.py < sample.json

or

cat sample.json | python json_formatter.py

where the sample.json is the file with JSON contents we'd like to flatten.

Example

The following JSON object:

{
    "a": 1,
    "b": true,
    "c": {
        "d": 3,
        "e": "test"
    }
}

should output:

{
    "a": 1,
    "b": true,
    "c.d": 3,
    "c.e": "test"
}

In this example the path to the terminal value 1 is "a" and the path to the terminal value 3 is "c.d".

Assumptions

  • The input file should be a JSON object
  • All keys named in the original object should be simple strings without ‘.’ characters
  • The input JSON should not contain arrays

Test

To run tests:

python -m unittest json_formatter_test.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages