I need help with my python assignment and I'm stuck can't find any solution for it. Convert CSV string format to JSON format

Joined
Oct 12, 2021
Messages
1
Reaction score
0
Please read the description to understand better what is the requirement of my python assignment thanks.

# Create a file with the name data_format.py
# Add the following functions to file data_format:
# function get_book_info(), the function askes the user to enter the following information:
# book title
# book ISBN
# book author last name
# book publisher
# year published
# book price in Canadian dollars.
# The function will eliminate leading and trailing spaces from title, ISBN, author name and publisher (use function strip ()).
# The function will return a string from the given information in the same order specified above, separated by forward slash (/)
# Note: price should be formatted to have two digits after the decimal point
# Function to_csv_format(), the function takes one parameter which is the string generated by get_book_info(), parse it and return a string of the provided information in a csv format.
# Function to_JSON_format(), the function takes a CSV formatted string and returns the corresponding JSON format string. Use String Methods find() ,string slicing and string concatenation to implement the required functionality.
# Create a main function as shown in the in-class lab section. Add function calls to get the book information, produce and display the csv
def get_book_info():
book_title = (input("Enter the book title: "))
book_ISBN = input("Enter book ISBN: ")
book_author_last_name = input("Enter author last name: ")
book_publisher = input("Enter book publisher: ")
year_published = input("Enter year published: ")
book_price = float(input("Book price: "))

book_title = book_title.strip()
book_ISBN = book_ISBN.strip()
book_author_last_name = book_author_last_name.strip()
book_publisher = book_publisher.strip()
year_published = year_published.strip()

return f"%s/%s/%s/%s/%s/%.2f"%(book_title,book_ISBN,book_author_last_name,book_publisher,year_published,book_price)


# Function to_csv_format(), the function takes one parameter which is the string generated by get_book_info(),
# parse it and return a string of the provided information in a csv format.

def to_csv_format(string_data):

string_to_csv_format = "".join(string_data)
return string_to_csv_format.replace("/",",")


#Function to_JSON_format(), the function takes a CSV formatted string and
#returns the corresponding JSON format string. Use String Methods find() ,
#string slicing and string concatenation to implement the required functionality.

def to_JSON_format(csv_formatted_string_to_json):

string = csv_formatted_string_to_json.replace(",",":")
return string

I NEED HELP WITH MY TO_JSON_FORMAT(), HOW I CAN CONVERT CSV STRING TO JSON FORMAT. THANKS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top