Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in csvToJson method. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions loklak.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def xmlToJson(self, xmlData = None):

def csvToJson(self, csvData = None, fieldnamesList = None):
"""Convert CSV to JSON as the service."""
jsonData = ''
jsonData = '[]'
if csvData:
data = csv.DictReader( csvData, fieldnames = fieldnamesList)
jsonData = json.dumps( [ row for row in data ] )
return out
return jsonData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the code doesn't enter the csvData if block, it ends up returning '' which is not a valid json. if the JSON is what needs to be returned then ideally it should return {}

Copy link
Author

@YJDave YJDave Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then that should be applied to xmlToJson method too.
This method not at all gives expected output json. Should I change the whole definition of this method?(which can generate right json data from csv)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! Thanks for catching that. Feel free to make a change to that too. 😄


def hello(self):
"""Retrieve a json response about the basic status of the server."""
Expand Down