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

  • SEARCH
  • Home
  • 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 8940921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:10:22+00:00 2026-06-15T11:10:22+00:00

i have the xml file, i need to convert into the json. the json

  • 0

i have the xml file, i need to convert into the json.
the json output is the partial convert of the xml, not whole xml is converted..

Reason you can find the output of the json, only partial is being converted.
remaining portion is omitted.

<?xml version="1.0"?>
<ASF_Service_ResponseVO typesig="155c0afe34b" id="1">
    <service type="String">OnboardingV2</service>
    <operation type="String">start_onboarding_session</operation>
    <requested_version type="String">1.0</requested_version>
    <actual_version type="String">1.0</actual_version>
    <server_info type="String">onboardingv2serv:start_onboarding_session&amp;CalThreadId=85&amp;TopLevelTxnStartTime=13b40fe91c4&amp;Host=L-BLR-00438534&amp;pid=3564</server_info>
    <result typesig="fff96cab366a5def" type="Onboarding::StartOnboardingSessionResponse" id="2">
        <onboarding_id type="String">137</onboarding_id>
        <success type="bool">true</success>
    </result>
</ASF_Service_ResponseVO>

ConvertXMLtoJSON.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javasample1;

//import net.sf.json.JSON;
//import net.sf.json.JSONObject; 
//import net.sf.json.xml.XMLSerializer;
import org.json.JSONObject;
import org.json.JSONException;
import org.json.XML;
import java.io.*;
/**
 *
 * @author gopc
 */
    public class ConvertXMLtoJSON{

        public static void main(String[] args) throws Exception 
        {
            try
            {

                File file = new File ("C:\\Users\\gopc\\Documents\\NetBeansProjects\\JavaSample1\\src\\javasample1\\Sample1.xml");
                InputStream inputStream = new FileInputStream(file);
                StringBuilder builder =  new StringBuilder();
                int ptr = 0;
                while ((ptr = inputStream.read()) != -1 )
                {
                    builder.append((char) ptr);
                }

                String xml  = builder.toString();
                JSONObject jsonObj = XML.toJSONObject(xml); 
                System.out.println(jsonObj);

                /*
                String xmlString  = "<?xml version=\"1.0\"?><ASF_Service_ResponseVO id=\"1\"><service type=\"String\">OnboardingV2</service><operation type=\"String\">start_onboarding_session</operation><requested_version type=\"String\">1.0</requested_version><actual_version type=\"String\">1.0</actual_version><server_info type=\"String\">onboardingv2serv:start_onboarding_session&amp;CalThreadId=85&amp;TopLevelTxnStartTime=13b40fe91c4&amp;Host=L-BLR-00438534&amp;pid=3564</server_info><result type=\"Onboarding::StartOnboardingSessionResponse\" id=\"2\"><onboarding_id type=\"String\">137</onboarding_id><success type=\"bool\">true</success></result></ASF_Service_ResponseVO>";

                JSONObject jsonObj = XML.toJSONObject(xmlString); 
                System.out.println(jsonObj.toString()); 
                */
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
}

output

run:
{"ASF_Service_ResponseVO":{"server_info":{"content":"onboardingv2serv:start_onboarding_session&CalThreadId=85&TopLevelTxnStartTime=13b40fe91c4&Host=L-BLR-00438534&pid=3564","type":"String"},"result":{"id":2,"typesig":"fff96cab366a5def","onboarding_id":{"content":137,"type":"String"},"type":"Onboarding::StartOnboardingSessionResponse","success":{"content":true,"type":"bool"}},"operation":{"content":"start_onboarding_session","type":"String"},"requested_version":{"content":1,"type":"String"},"service":{"content":"OnboardingV2","type":"String"},"actual_version":{"content":1,"type":"String"}}}

BUILD SUCCESSFUL (total time: 0 seconds)

The resulting JSON object formated:

{
    "ASF_Service_ResponseVO": {
        "server_info": {
             "content":"onboardingv2serv:start_onboarding_session&CalThreadId=85&TopLevelTxnStartTime=13b40fe91c4&Host=L-BLR-00438534&pid=3564",
             "type":"String"
        },
        "result": {
            "id":2,
            "typesig":"fff96cab366a5def",
            "onboarding_id": {
                 "content":137,
                 "type":"String"
            },
            "type":"Onboarding::StartOnboardingSessionResponse",
            "success": {
                "content":true,
                "type":"bool"
            }
        },
        "operation": {
            "content":"start_onboarding_session",
            "type":"String"
        },
        "requested_version":{
            "content":1,
            "type":"String"
        },
        "service":{
            "content":"OnboardingV2",
            "type":"String"},
        }
        "actual_version":{
             "content":1,
             "type":"String"
        }
    }
}
  • 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-15T11:10:23+00:00Added an answer on June 15, 2026 at 11:10 am

    If you don’t expect the same order of xml, the following is the output json

    {
        "ASF_Service_ResponseVO":{
            "server_info":{
                "content":"onboardingv2serv:start_onboarding_session&CalThreadId=85&TopLevelTxnStartTime=13b40fe91c4&Host=L-BLR-00438534&pid=3564",
                "type":"String"
            },
            "id":"1",
            "result":{
                "id":"2",
                "typesig":"fff96cab366a5def",
                "onboarding_id":{
                    "content":"137",
                    "type":"String"
                },
                "type":"Onboarding::StartOnboardingSessionResponse",
                "success":{
                    "content":"true",
                    "type":"bool"
                }
            },
            "operation":{
                "content":"start_onboarding_session",
                "type":"String"
            },
            "requested_version":{
                "content":"1.0",
                "type":"String"
            },
            "typesig":"155c0afe34b",
            "service":{
                "content":"OnboardingV2",
                "type":"String"
            },
            "actual_version":{
                "content":"1.0",
                "type":"String"
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML file that I need to convert to JSON in
I need to Convert a CSV into an XML document. The examples I have
I have a Perl script to convert the XML file below into a hash:
I need to convert .ass subtitles file into .xml file. So far I did
I have xml file and I need to convert the text that I get
I need to load an XML file and convert the contents into an object-oriented
I have an XML file that I need to deserialize into an object similar
I have an xml file I need to modify: ... </web-app> I want to
I have a xml file which I need to open with Microsoft Word 2007.
I have an XML file and I need to extract testname from all the

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.