Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:41:16+00:00 2026-06-08T16:41:16+00:00

I am new to python and django. For my application in my django view,

  • 0

I am new to python and django.

For my application in my django view, I am accepting array (and sub arrays) of JSON objects as request, by using json.loads I am trying to parse and iterate thru JSON objects but facing issues while parsing.

my javascript object sent from client is

var JSONObject = { 
       "employees_companyA": 
        [
          { "firstName":"John" , "lastName":"Doe" }, 
          { "firstName":"Anna" , "lastName":"Smith" }, 
          { "firstName":"Peter" , "lastName":"Jones" }
        ],

      "employees_companyB": 
        [
          { "firstName":"John" , "lastName":"Doe" }, 
          { "firstName":"Anna" , "lastName":"Smith" }, 
          { "firstName":"Peter" , "lastName":"Jones" }
        ]
     };

What is the best way to parse above two objects and read firstName, lastName for same.

I tried using o[“firstName”], o.firstName etc (below is my code snippet)

   json_obj = json.loads(request.POST['json_test']) 
   for o in json_obj:
        temp_arr.append(o["firstName"])

I am sure this would be pretty straightforward but I couldn’t find exact help here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:41:17+00:00Added an answer on June 8, 2026 at 4:41 pm

    The top-level element of your JSON structure is not a list, but a mapping. It’s keys are of the form "employees_companyA", "employees_companyB", etc.

    You need to thus address that structure using the python mapping interface instead:

    for value in json_obj.itervalues():
         temp_arr.append(value[0]["firstName"])
    

    or as a one-liner:

    temp_arr = [value[0]['firstName'] for value in json_obj.itervalues()]
    

    Both use the .itervalues() method on json_obj to loop over all the values in the structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python and I am using django for student database application
I'm fairly new to both Django and Python. This is my first time using
I have new to python and django I am creating poll application and in
im new to django and python , im trying to do runserver on a
I am using python logging in my django application. A class that connects to
I'm new to Django (and Python), and am trying to figure out how to
I have a simple blog application written in Python, using Django. I use Git
I'm really new to Python and Django. I created a class in Python that
I'm new with Django and python. I have a problem. Is there a way,
I am new on Django and Python. I want to write a program with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.