0

I'm mapping my arrays (there's quite a bit). So the idea is to just stringify all objects/everything within the array.

  const studentInfoObj = students.map(value => (
      // for each student return json string of the objects
      // how can I just stringify everything within the array?
      // but not the array itself. Just all the objects inside?
      return JSON.stringify(???);
  ));

Here's the json currently so s

{"Michael00043":
     // stringify from this point
     [
          {"student_num":"20293290000HJ93",
           "campus":"McHale",
           "major":"PSI"
          },
     ],
      ... more objects
     [
          {"medical_doc":"st.laurance hos",
           "emergency_contact":"Adam Harley",
           "blood_type":"O"
          },
          {"hospital":"st.laurance hos",
           "ward":"B",
          },
     ]
...
4
  • your solution is right. what do you want? Commented Jun 2, 2016 at 18:35
  • Your JSON is badly formatted. Can you please give a valid example. You have a start [ but no close ]. Commented Jun 2, 2016 at 18:35
  • @IMTheNachoMan yeah sorry it definitely is. It's extremely long. I just tried to post a simple example of it. Commented Jun 2, 2016 at 19:14
  • @rishabhdev well i'm just trying to figure out what to stringify. if i return JSON.stringify(value); it just prints out "Michael00043".. But I'm trying to stringify everything within Michael00043/student Commented Jun 2, 2016 at 19:15

1 Answer 1

3

Is this what you mean?

var students = {
  "Michael00043": [{
    "student_num": "20293290000HJ93",
    "campus": "McHale",
    "major": "PSI"
  }, {
    "medical_doc": "st.laurance hos",
    "emergency_contact": "Adam Harley",
    "blood_type": "O"
  }]


};

// loop through each student
for (student in students) {
  // stringy each value in the array that each student is
  students[student] = students[student].map(value => JSON.stringify(value));
}

console.log(students);

Sign up to request clarification or add additional context in comments.

1 Comment

This looks like it would work. I'm just having a hard time with jsx syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.