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 6993299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:44:48+00:00 2026-05-27T19:44:48+00:00

So I have a json object which has a structure like so: { John

  • 0

So I have a json object which has a structure like so:

{
"John Doe": [
    {
        "childName": "Harry",
        "childAge": 15,
        "childGender": "Male"
    },
    {
        "childName": "Sally",
        "childAge": 9,
        "childGender": "Female"
    },
],
"Miss Piggy": [
    {
        "childName": "Jane",
        "childAge": 20,
        "childGender": "Female"
    }
],

}

What I want to do is be able to make a query for the childName, childAge, or childGender, and return that sub-object if it’s found.

For example:

searchJson($jsonObj, 'childName', 'Sally') // returns {"childName":"Sally", "childAge":9,"childGender":"Female"}

What would be the best method at going at this?

  • 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-05-27T19:44:49+00:00Added an answer on May 27, 2026 at 7:44 pm
    function searchJson($obj, $field, $value) {
        foreach($obj as $item) {
            foreach($item as $child) {
                if(isset($child->$field) && $child->$field == $value) {
                    return $child;
                }
            }
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Play framework. I have a JSONObject which has a structure like the
I have a JSON object items which has few items that I want to
I have a form field which requires a json object as its value when
I have a request that returns a JSON object with a single property which
I have several TextField columns on my UserProfile object which contain JSON objects. I've
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have MySQL database, where I store the following BLOB (which contains JSON object)
I have a fairly complex object which has some C# code written to render
I have an object which has a circular reference to another object. Given the
I have a JSON string and I'd like to use to compose an object.

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.