troubleshooting Question

Return JSON from php script

Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox asked on
JavaPHP
2 Comments1 Solution510 ViewsLast Modified:
Hi,

I have a PHP script. I want to output a result as a JSON string/object. I'd like the output to look like this:

{
  "message": {
    "text": "Students fetched ok!",
  },
  "students": [
    {
      "student_id": "123",
      "student_name": "john doe"
    },
    {
      "student_id": "456",
      "student_name": "jane doe"
    }
  ]
}

not sure where to get started though. Looks like this is one big JSON object, which has a 'message' object, then an array of students (which I'll fetch from a database). What's a standard way people generate these types of responses from php scripts?

Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros