Home > database >  Python json.loads returning JSONDecodeError Expecting ',' delimiter
Python json.loads returning JSONDecodeError Expecting ',' delimiter

Time:12-07

I am trying to parse a JSON raw string using json.loads but its throwing following error

JSONDecodeError at /octopus/entries/53/test_sample_job/
Expecting ',' delimiter: line 3 column 27 (char 48)

My json string data is as follows and I am getting error when i did json.loads(data)

data = {
    "name": "Shea",
    "content": "<p style="text-align:left">Job Description</p><p style="text-align:inherit"></p>Have you heard about phenom? phenom is an innovative, global healthcare leader committed to improving health and well-being in 140 countries around the world. We continue to focus our research on conditions that affect millions of people around the world - diseases like Alzheimer's, Diabetes and Cancer - while further expanding our strengths in areas such as vaccines and biologics. We aspire to be the best healthcare company in the world and are dedicated to providing leading innovations and solutions for tomorrow. &nbsp; phenom’s Global Human Health (GHH) Division abides by a “patient first, profits later” ideology. Results-driven and ambitious, this team of individuals represents a functional balance between meeting company objectives and the needs of people around the world. The division is comprised of sales and marketing professionals who are passionate about their role in bringing phenom's prescription medicines, vaccines, and other medical products to our customers worldwide. Who are we looking for? A strong Professional for the position of the Hospital Specialist in Oncology who is responsible for promoting oncology brands within given accounts. On this position you would need to understand customers’ needs and have strong business acumen. It is important YOU are being equipped with excellent medical knowledge where you can transfer key medical data into customer / patient benefits. Expected Qualification of YOURS: - University degree preferably life science - 3  years of experience working in a customer-facing role - Strong knowledge of customer/business strategy - Understanding of local healthcare and reimbursement systems - English language preferred &nbsp; Key competencies: - Customer &amp; Market Insights:&nbsp;Ability to develop a deep understanding of customer needs, behaviours and goals, as well as market dynamics, competitor analysis and trends to improve overall business outcomes. - Customer Engagement:&nbsp;Ability to identify and appropriately build and maintain long-term, sustainable relationships with customers, external stakeholders and key influencers through a variety of relationship-building approaches. - Strategic Business Management:&nbsp;Ability to set strategic plans, consider execution trade-offs and continuously adjust approaches to maximize business performance and increase sales. - Excellent medical Product knowledge&nbsp;– excellent evidence-basedmedicine data knowledge. Ability to transfer medical data into customer / patients benefits &nbsp; Skills Required: - Driving license B - Advance Medical knowledge of oncology therapy area preferably or demonstrate high learning agility and interest in evidence-based medicine data and ability to transfer them into customer / patients benefits &nbsp; Leadership behaviours: - Drive result - Focus on customer and patient - Demonstrate ethics and integrity - High learning agility &nbsp; YOUR primary activities&nbsp;include but are not limited to: &nbsp; Account Understanding and Analysis - Understanding decision-making processes within the account, patient flow - Identifying Account Stakeholders and understanding their perspectives on phenom, our competitors - Completing a competitor analysis for the account - Obtaining an in-depth understanding of the account’s unmet and evolving needs &nbsp; Account Plan Development - Identifying short and long-term business opportunities. - Defining objectives for the account - Developing a plan for the Account that contains the account needs and perspectives as well as considers competitive and business challenges - Determining how to appropriately leverage cross-functional internal resources to maximize potential - Defining account metrics and a tracking plan &nbsp; Account Plan Implementation and Tracking - Developing and maintaining long-term engagements with customers/stakeholders within the Accounts that are responsible for treatment of the respective patients (all relevant HCPs) as well as product purchasing &nbsp;(hospital management, pharmacists) - Conducting product and value-based negotiation &nbsp;<p style="text-align:inherit"></p><p style="text-align:left"><b>English Job Description:</b></p><p style="text-align:inherit"></p><p style="text-align:inherit"></p><p></p><p><b>Search Firm Representatives Please Read Carefully&nbsp;</b><br>phenom &amp; Co., Inc., Kenilworth, NJ, USA, also known as phenom phenom &amp; phenom Corp., Kenilworth, NJ, USA, does not accept unsolicited assistance from search firms for employment opportunities. All CVs / resumes submitted by search firms to any employee at our company without a valid written search agreement in place for this position will be deemed the sole property of our company. &nbsp;No fee will be paid in the event a candidate is hired by our company as a result of an agency referral where no pre-existing agreement is in place. Where agency agreements are in place, introductions are position specific. Please, no phone calls or emails.&nbsp;</p><p style="text-align:inherit"></p><p style="text-align:left"><b>Employee Status: </b></p>Regular<p style="text-align:inherit"></p><p style="text-align:left"><b>Relocation:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>VISA Sponsorship:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b><span>Travel Requirements:</span></b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Flexible Work Arrangements:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Shift:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Valid Driving License:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Hazardous Material(s):</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Number of Openings: </b></p>1",
    "street_name": "Bartol",
    "city": "Brentwood",
    "country": "Slovenia",
    "continent": "Europe"
}

I observed that the issue is happening in the content value where I am having HTML code that contains double quotes. I have tried various solutions like json.loads(repr(data)) and html.escape(json.loads(data)) but still my error is not getting resolved.

I even tried to replace all the double quotes with empty string but then it threw an error saying too many values to unpack

I wanted to try this solution but unable to figure out how to use r in this case as my string is stored in a variable data.

Please suggest a workaround for this inorder to parse this json.

CodePudding user response:

You have double quotes within the quotes of the string for the content. Use a """ for the content to use a string literal.

Or add an escape character for every quote mark as \" within the content string.

data = {
        "name": "Shea",
        "content": """<p style="text-align:left">Job Description</p><p style="text-align:inherit"></p>Have you heard about phenom? phenom is an innovative, global healthcare leader committed to improving health and well-being in 140 countries around the world. We continue to focus our research on conditions that affect millions of people around the world - diseases like Alzheimer's, Diabetes and Cancer - while further expanding our strengths in areas such as vaccines and biologics. We aspire to be the best healthcare company in the world and are dedicated to providing leading innovations and solutions for tomorrow. &nbsp; phenom’s Global Human Health (GHH) Division abides by a “patient first, profits later” ideology. Results-driven and ambitious, this team of individuals represents a functional balance between meeting company objectives and the needs of people around the world. The division is comprised of sales and marketing professionals who are passionate about their role in bringing phenom's prescription medicines, vaccines, and other medical products to our customers worldwide. Who are we looking for? A strong Professional for the position of the Hospital Specialist in Oncology who is responsible for promoting oncology brands within given accounts. On this position you would need to understand customers’ needs and have strong business acumen. It is important YOU are being equipped with excellent medical knowledge where you can transfer key medical data into customer / patient benefits. Expected Qualification of YOURS: - University degree preferably life science - 3  years of experience working in a customer-facing role - Strong knowledge of customer/business strategy - Understanding of local healthcare and reimbursement systems - English language preferred &nbsp; Key competencies: - Customer &amp; Market Insights:&nbsp;Ability to develop a deep understanding of customer needs, behaviours and goals, as well as market dynamics, competitor analysis and trends to improve overall business outcomes. - Customer Engagement:&nbsp;Ability to identify and appropriately build and maintain long-term, sustainable relationships with customers, external stakeholders and key influencers through a variety of relationship-building approaches. - Strategic Business Management:&nbsp;Ability to set strategic plans, consider execution trade-offs and continuously adjust approaches to maximize business performance and increase sales. - Excellent medical Product knowledge&nbsp;– excellent evidence-basedmedicine data knowledge. Ability to transfer medical data into customer / patients benefits &nbsp; Skills Required: - Driving license B - Advance Medical knowledge of oncology therapy area preferably or demonstrate high learning agility and interest in evidence-based medicine data and ability to transfer them into customer / patients benefits &nbsp; Leadership behaviours: - Drive result - Focus on customer and patient - Demonstrate ethics and integrity - High learning agility &nbsp; YOUR primary activities&nbsp;include but are not limited to: &nbsp; Account Understanding and Analysis - Understanding decision-making processes within the account, patient flow - Identifying Account Stakeholders and understanding their perspectives on phenom, our competitors - Completing a competitor analysis for the account - Obtaining an in-depth understanding of the account’s unmet and evolving needs &nbsp; Account Plan Development - Identifying short and long-term business opportunities. - Defining objectives for the account - Developing a plan for the Account that contains the account needs and perspectives as well as considers competitive and business challenges - Determining how to appropriately leverage cross-functional internal resources to maximize potential - Defining account metrics and a tracking plan &nbsp; Account Plan Implementation and Tracking - Developing and maintaining long-term engagements with customers/stakeholders within the Accounts that are responsible for treatment of the respective patients (all relevant HCPs) as well as product purchasing &nbsp;(hospital management, pharmacists) - Conducting product and value-based negotiation &nbsp;<p style="text-align:inherit"></p><p style="text-align:left"><b>English Job Description:</b></p><p style="text-align:inherit"></p><p style="text-align:inherit"></p><p></p><p><b>Search Firm Representatives Please Read Carefully&nbsp;</b><br>phenom &amp; Co., Inc., Kenilworth, NJ, USA, also known as phenom phenom &amp; phenom Corp., Kenilworth, NJ, USA, does not accept unsolicited assistance from search firms for employment opportunities. All CVs / resumes submitted by search firms to any employee at our company without a valid written search agreement in place for this position will be deemed the sole property of our company. &nbsp;No fee will be paid in the event a candidate is hired by our company as a result of an agency referral where no pre-existing agreement is in place. Where agency agreements are in place, introductions are position specific. Please, no phone calls or emails.&nbsp;</p><p style="text-align:inherit"></p><p style="text-align:left"><b>Employee Status: </b></p>Regular<p style="text-align:inherit"></p><p style="text-align:left"><b>Relocation:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>VISA Sponsorship:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b><span>Travel Requirements:</span></b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Flexible Work Arrangements:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Shift:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Valid Driving License:</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Hazardous Material(s):</b></p><p style="text-align:inherit"></p><p style="text-align:left"><b>Number of Openings: </b></p>1""",
        "street_name": "Bartol",
        "city": "Brentwood",
        "country": "Slovenia",
        "continent": "Europe"
    }
  • Related