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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:12:10+00:00 2026-06-16T05:12:10+00:00

i found many examples to parse java object to Json. Thanks for that.But i

  • 0

i found many examples to parse java object to Json.
Thanks for that.But i have one issue, i want Json in following format

{
  "parent":
  {
    "sub-parent-1":
    {
      "child-1": 1,
      "child-2": 2
    },
    "sub-parent-2":
    {
      "child-2": 3
    }
  }
}

Is it possible with java.
Please answer.Thanks in advanced..

  • 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-16T05:12:12+00:00Added an answer on June 16, 2026 at 5:12 am

    Create Current Json String as in Java :

        JSONObject parent = new JSONObject();
        JSONObject subparentone = new JSONObject();
    
        JSONObject subparenttwo = new JSONObject();
    
        subparentone.put("child-1", "1");
        subparentone.put("child-2", "2");
    
        subparenttwo.put("child-2", "3");
    
        parent.put("sub-parent-1", subparentone);
        parent.put("sub-parent-2", subparenttwo);
    
       JSONObject finalparent = new JSONObject();
       finalparent.put("parent", parent);
    

    and finalparent JsonObject output as:

    {
      "parent": {
        "sub-parent-1": {
          "child-1": 1,
          "child-2": 2
        },
        "sub-parent-2": {
          "child-2": 3
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found many examples for older versions of CherryPy but they each referenced importing
I've found many examples on how to search for files that exist in a
i found many related questions here. I have a simple java program . it
I have a problem with writing a Cartesian power function. I found many examples
Firstly, I have found many examples of how to grab data from a db
I found many examples of generic repository using LINQ to SQL. However there is
I have found many great answers to this from a year ago (when it
I've found many definitions of the 'var' statement but most of them are incomplete
I've found many examples about UTC tables and php date methods to convert it,
I searched internet and found examples with setting only one field of property: xprop

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.