added nesting options to route handler function
renamed createNestedJSON to convertToNested
added if: checks if the object has 'key' property before pushing into array