ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexWebSphere Message Broker SupportHow to convert XML to JSON Array

Post new topicReply to topic
How to convert XML to JSON Array View previous topic :: View next topic
Author Message
venkatachalam
PostPosted: Tue Jul 04, 2017 10:38 pm Post subject: How to convert XML to JSON Array Reply with quote

Newbie

Joined: 24 Jun 2017
Posts: 3

The below XML message is input
Code:
<Item>
            <DeviceSerialNo>8800099004</DeviceSerialNo>
            <DeviceCategory>MTR_3PH_WC_ELEC2</DeviceCategory>
            <DeviceDescription>Device</DeviceDescription>
            <Manufacturer>ITRON</Manufacturer>
            <ManufacturerYear>2010</ManufacturerYear>
            <AMS>IEE</AMS>
            <AMCG>0101</AMCG>
            <RegisterGroup>3I01C1S1</RegisterGroup>
            <AMIData>RMR</AMIData>
            <FunctionClass>RMRMTR</FunctionClass>
            <DeviceUserStatus>
               <InternalStatusNo>E0007</InternalStatusNo>
               <Status>AVLB</Status>
               <DescriptionStatus>Device is available</DescriptionStatus>
            </DeviceUserStatus>
            <RegisterDetail>
               <Register>001</Register>
               <RegisterType>01</RegisterType>
               <RegisterTypeText>Accumulative kWh</RegisterTypeText>
               <RegisterFactor>1.00000</RegisterFactor>
               <PredecimalPlaces>09</PredecimalPlaces>
               <DecimalPlaces>00</DecimalPlaces>
               <TransformationRatio>0.000</TransformationRatio>
               <PrimaryVoltage>0</PrimaryVoltage>
               <SecondaryVoltage>0.0</SecondaryVoltage>
               <PrimaryCurrent>0.0</PrimaryCurrent>
               <SecondaryCurrent>0.00</SecondaryCurrent>
               <UnitofMeasurement>KWH</UnitofMeasurement>
            
               <ParentDevice>
                  <AllocationType>87</AllocationType>
              <ControllingDevice>8800099087</ControllingDevice>
               </ParentDevice>
               <ParentDevice>
                  <AllocationType>88</AllocationType>
                  <ControllingDevice>8800099088</ControllingDevice>
               </ParentDevice>
            
            </RegisterDetail>
            <RegisterDetail>
               <Register>002</Register>
               <RegisterType>11</RegisterType>
               <RegisterTypeText>Accumulative kVarh</RegisterTypeText>
               <RegisterFactor>1.00000</RegisterFactor>
               <PredecimalPlaces>09</PredecimalPlaces>
               <DecimalPlaces>00</DecimalPlaces>
               <TransformationRatio>0.000</TransformationRatio>
               <PrimaryVoltage>0</PrimaryVoltage>
               <SecondaryVoltage>0.0</SecondaryVoltage>
               <PrimaryCurrent>0.0</PrimaryCurrent>
               <SecondaryCurrent>0.00</SecondaryCurrent>
               <UnitofMeasurement>VAR</UnitofMeasurement>
            
               <ParentDevice>
                  <AllocationType>89</AllocationType>
              <ControllingDevice>8800099089</ControllingDevice>
               </ParentDevice>
               <ParentDevice>
                  <AllocationType>90</AllocationType>
                  <ControllingDevice>8800099090</ControllingDevice>
               </ParentDevice>
            
               <ParentDevice>
                  <AllocationType>91</AllocationType>
              <ControllingDevice>8800099091</ControllingDevice>
               </ParentDevice>
               <ParentDevice>
                  <AllocationType>92</AllocationType>
                  <ControllingDevice>8800099092</ControllingDevice>
               </ParentDevice>
          
            </RegisterDetail>
           
            </Item>
Back to top
View user's profile Send private message
smdavies99
PostPosted: Tue Jul 04, 2017 10:49 pm Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6077
Location: Somewhere over the Rainbow this side of Never-never land.

What have you tried? What went wrong?

We are really here to help yourself do your job and not to do your job for you (unless you have a signed Purchase Order ready and waiting )

There are a number of posts here that deal with JSON and JSON formatting. May I humbly suggest that you look at them and try to solve your problem yourself. Then if you run into problems please come back and tell us what you did and where it went wrong.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
venkatachalam
PostPosted: Tue Jul 04, 2017 10:58 pm Post subject: Reply with quote

Newbie

Joined: 24 Jun 2017
Posts: 3

Code:
[
    {
        "DeviceSerialNo": "8800099004",
        "DeviceCategory": "MTR_3PH_WC_ELEC2",
        "DeviceDescription": "Device",
        "Manufacturer": "ITRON",
        "ManufacturerYear": "2010",
        "AMS": "IEE",
        "AMCG": "0101",
        "RegisterGroup": "3I01C1S1",
        "AMIData": "RMR",
        "FunctionClass": "RMRMTR",
        "DeviceUserStatus": {
            "InternalStatusNo": "E0007",
            "Status": "AVLB",
            "DescriptionStatus": "Device is available"
        },
        "RegisterDetail": [
            "002",
            "11",
            "Accumulative kVarh",
            "1.00000",
            "09",
            "00",
            "0.000",
            "0",
            "0.0",
            "0.0",
            "0.00",
            "VAR",
            {
                "AllocationType": "89",
                "ControllingDevice": "8800099089"
            },
            {
                "AllocationType": "90",
                "ControllingDevice": "8800099090"
            },
            {
                "AllocationType": "91",
                "ControllingDevice": "8800099091"
            },
            {
                "AllocationType": "92",
                "ControllingDevice": "8800099092"
            }
        ]
    }
]

This is the output i get but this is not exact output


The code i created is
Code:
SET OutputRoot.JSON.Data.Item.DeviceSerialNo = InputRoot.XMLNSC.Item.DeviceSerialNo;
      SET OutputRoot.JSON.Data.Item.DeviceCategory = InputRoot.XMLNSC.Item.DeviceCategory;
      SET OutputRoot.JSON.Data.Item.DeviceDescription = InputRoot.XMLNSC.Item.DeviceDescription;
      SET OutputRoot.JSON.Data.Item.Manufacturer = InputRoot.XMLNSC.Item.Manufacturer;
      SET OutputRoot.JSON.Data.Item.ManufacturerYear = InputRoot.XMLNSC.Item.ManufacturerYear;
      SET OutputRoot.JSON.Data.Item.AMS = InputRoot.XMLNSC.Item.AMS;
      SET OutputRoot.JSON.Data.Item.AMCG = InputRoot.XMLNSC.Item.AMCG;
      SET OutputRoot.JSON.Data.Item.RegisterGroup = InputRoot.XMLNSC.Item.RegisterGroup;
      SET OutputRoot.JSON.Data.Item.AMIData = InputRoot.XMLNSC.Item.AMIData;
      SET OutputRoot.JSON.Data.Item.FunctionClass = InputRoot.XMLNSC.Item.FunctionClass;
      
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.InternalStatusNo = InputRoot.XMLNSC.Item.DeviceUserStatus.InternalStatusNo;
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.Status = InputRoot.XMLNSC.Item.DeviceUserStatus.Status;
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.DescriptionStatus = InputRoot.XMLNSC.Item.DeviceUserStatus.DescriptionStatus;
      
      --CREATE FIELD OutputRoot.JSON.Data IDENTITY(JSON.Array)Data;
      
      SET OutputRoot.JSON.Data TYPE = JSON.Array;
      CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail IDENTITY(JSON.Array)RegisterDetail;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.Register = InputRoot.XMLNSC.Item.RegisterDetail[1].Register;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterType = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterTypeText = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterTypeText;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterFactor = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterFactor;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PredecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[1].PredecimalPlaces;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.DecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[1].DecimalPlaces;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.TransformationRatio = InputRoot.XMLNSC.Item.RegisterDetail[1].TransformationRatio;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[1].PrimaryVoltage;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[1].SecondaryVoltage;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[1].PrimaryCurrent;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[1].SecondaryCurrent;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.UnitofMeasurement = InputRoot.XMLNSC.Item.RegisterDetail[1].UnitofMeasurement;
      
      --CREATE LASTCHILD OF OutputRoot.JSON IDENTITY(JSON.Array)Data;
      --CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice IDENTITY(JSON.Array)ParentDevice;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[1].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[1].ControllingDevice;
      
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[2].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[2].ControllingDevice;
      
      --CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail[2] IDENTITY(JSON.Array)RegisterDetail[2];
      SET OutputRoot.JSON.Data.Item.RegisterDetail.Register = InputRoot.XMLNSC.Item.RegisterDetail[2].Register;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterType = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterTypeText = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterTypeText;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterFactor = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterFactor;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PredecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[2].PredecimalPlaces;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.DecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[2].DecimalPlaces;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.TransformationRatio = InputRoot.XMLNSC.Item.RegisterDetail[2].TransformationRatio;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[2].PrimaryVoltage;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[2].SecondaryVoltage;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[2].PrimaryCurrent;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[2].SecondaryCurrent;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.UnitofMeasurement = InputRoot.XMLNSC.Item.RegisterDetail[2].UnitofMeasurement;
      
      --CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice IDENTITY(JSON.Array)ParentDevice;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[1].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[1].ControllingDevice;
      
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[2].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[2].ControllingDevice;
      
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[3].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[3].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[3].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[3].ControllingDevice;
      
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[4].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[4].AllocationType;
      SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[4].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[4].ControllingDevice;
Back to top
View user's profile Send private message
smdavies99
PostPosted: Wed Jul 05, 2017 1:08 am Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6077
Location: Somewhere over the Rainbow this side of Never-never land.

1) Please edit your posts to use tags around code and xml. The [C o d e] tags is at the top of the edit box. It really makes your posts easier to read.
2) Your code is messy and inefficient. Please lean how to use REFERENCES
3) Why are the create field statements commented out?
4) Ok, so we got some output and some ESQL. But you have not told us what is wrong with the output.
I'm (and nor is anyone else here) not a mind reader.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
Android 23
PostPosted: Wed Jul 05, 2017 3:10 am Post subject: Reply with quote

Apprentice

Joined: 27 Mar 2017
Posts: 34

venkatachalam wrote:
[
{
"DeviceSerialNo": "8800099004",
"DeviceCategory": "MTR_3PH_WC_ELEC2",
"DeviceDescription": "Device",
"Manufacturer": "ITRON",
"ManufacturerYear": "2010",
"AMS": "IEE",
"AMCG": "0101",
"RegisterGroup": "3I01C1S1",
"AMIData": "RMR",
"FunctionClass": "RMRMTR",
"DeviceUserStatus": {
"InternalStatusNo": "E0007",
"Status": "AVLB",
"DescriptionStatus": "Device is available"
},
"RegisterDetail": [
"002",
"11",
"Accumulative kVarh",
"1.00000",
"09",
"00",
"0.000",
"0",
"0.0",
"0.0",
"0.00",
"VAR",
{
"AllocationType": "89",
"ControllingDevice": "8800099089"
},
{
"AllocationType": "90",
"ControllingDevice": "8800099090"
},
{
"AllocationType": "91",
"ControllingDevice": "8800099091"
},
{
"AllocationType": "92",
"ControllingDevice": "8800099092"
}
]
}
]
This is the output i get but this is not exact output


The code i created is
SET OutputRoot.JSON.Data.Item.DeviceSerialNo = InputRoot.XMLNSC.Item.DeviceSerialNo;
SET OutputRoot.JSON.Data.Item.DeviceCategory = InputRoot.XMLNSC.Item.DeviceCategory;
SET OutputRoot.JSON.Data.Item.DeviceDescription = InputRoot.XMLNSC.Item.DeviceDescription;
SET OutputRoot.JSON.Data.Item.Manufacturer = InputRoot.XMLNSC.Item.Manufacturer;
SET OutputRoot.JSON.Data.Item.ManufacturerYear = InputRoot.XMLNSC.Item.ManufacturerYear;
SET OutputRoot.JSON.Data.Item.AMS = InputRoot.XMLNSC.Item.AMS;
SET OutputRoot.JSON.Data.Item.AMCG = InputRoot.XMLNSC.Item.AMCG;
SET OutputRoot.JSON.Data.Item.RegisterGroup = InputRoot.XMLNSC.Item.RegisterGroup;
SET OutputRoot.JSON.Data.Item.AMIData = InputRoot.XMLNSC.Item.AMIData;
SET OutputRoot.JSON.Data.Item.FunctionClass = InputRoot.XMLNSC.Item.FunctionClass;

SET OutputRoot.JSON.Data.Item.DeviceUserStatus.InternalStatusNo = InputRoot.XMLNSC.Item.DeviceUserStatus.InternalStatusNo;
SET OutputRoot.JSON.Data.Item.DeviceUserStatus.Status = InputRoot.XMLNSC.Item.DeviceUserStatus.Status;
SET OutputRoot.JSON.Data.Item.DeviceUserStatus.DescriptionStatus = InputRoot.XMLNSC.Item.DeviceUserStatus.DescriptionStatus;

--CREATE FIELD OutputRoot.JSON.Data IDENTITY(JSON.Array)Data;

SET OutputRoot.JSON.Data TYPE = JSON.Array;
CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail IDENTITY(JSON.Array)RegisterDetail;
SET OutputRoot.JSON.Data.Item.RegisterDetail.Register = InputRoot.XMLNSC.Item.RegisterDetail[1].Register;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterType = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterTypeText = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterTypeText;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterFactor = InputRoot.XMLNSC.Item.RegisterDetail[1].RegisterFactor;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PredecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[1].PredecimalPlaces;
SET OutputRoot.JSON.Data.Item.RegisterDetail.DecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[1].DecimalPlaces;
SET OutputRoot.JSON.Data.Item.RegisterDetail.TransformationRatio = InputRoot.XMLNSC.Item.RegisterDetail[1].TransformationRatio;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[1].PrimaryVoltage;
SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[1].SecondaryVoltage;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[1].PrimaryCurrent;
SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[1].SecondaryCurrent;
SET OutputRoot.JSON.Data.Item.RegisterDetail.UnitofMeasurement = InputRoot.XMLNSC.Item.RegisterDetail[1].UnitofMeasurement;

--CREATE LASTCHILD OF OutputRoot.JSON IDENTITY(JSON.Array)Data;
--CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice IDENTITY(JSON.Array)ParentDevice;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[1].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[1].ControllingDevice;

SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[2].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[1].ParentDevice[2].ControllingDevice;

--CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail[2] IDENTITY(JSON.Array)RegisterDetail[2];
SET OutputRoot.JSON.Data.Item.RegisterDetail.Register = InputRoot.XMLNSC.Item.RegisterDetail[2].Register;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterType = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterTypeText = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterTypeText;
SET OutputRoot.JSON.Data.Item.RegisterDetail.RegisterFactor = InputRoot.XMLNSC.Item.RegisterDetail[2].RegisterFactor;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PredecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[2].PredecimalPlaces;
SET OutputRoot.JSON.Data.Item.RegisterDetail.DecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[2].DecimalPlaces;
SET OutputRoot.JSON.Data.Item.RegisterDetail.TransformationRatio = InputRoot.XMLNSC.Item.RegisterDetail[2].TransformationRatio;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[2].PrimaryVoltage;
SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[2].SecondaryVoltage;
SET OutputRoot.JSON.Data.Item.RegisterDetail.PrimaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[2].PrimaryCurrent;
SET OutputRoot.JSON.Data.Item.RegisterDetail.SecondaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[2].SecondaryCurrent;
SET OutputRoot.JSON.Data.Item.RegisterDetail.UnitofMeasurement = InputRoot.XMLNSC.Item.RegisterDetail[2].UnitofMeasurement;

--CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice IDENTITY(JSON.Array)ParentDevice;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[1].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[1].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[1].ControllingDevice;

SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[2].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[2].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[2].ControllingDevice;

SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[3].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[3].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[3].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[3].ControllingDevice;

SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[4].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[4].AllocationType;
SET OutputRoot.JSON.Data.Item.RegisterDetail.ParentDevice[4].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[2].ParentDevice[4].ControllingDevice;



Code:
 CREATE FIELD OutputRoot.JSON.Data.Details.HCRTable IDENTITY (JSON.Array) HCRTable;
      SET OutputRoot.JSON.Data.Details.HCRTable.Item[1].HCRTable1=InputRoot.XMLNSC.Details.HCRTable[1].HCRTable1;
      SET OutputRoot.JSON.Data.Details.HCRTable.Item[2].HCRTable2=InputRoot.XMLNSC.Details.HCRTable[2].HCRTable2;


Try in this way..
And your code looks too clumsy.
Using Item doesn't change your tags and gets removed will displaying output.

Thanks & Regards.
Android 23
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jul 05, 2017 3:46 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17384

Use reference variables instead of [x] values.
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
Android 23
PostPosted: Wed Jul 05, 2017 4:04 am Post subject: Reply with quote

Apprentice

Joined: 27 Mar 2017
Posts: 34

mqjeff wrote:
Use reference variables instead of [x] values.


I agree with you to use 'x'. But if we use 'x', then we need to write loop for that condition. And it can be used for 2 values and more than that, it's better to use loop

Thanks & Regards
Android 23.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jul 05, 2017 4:19 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17384

Android 23 wrote:
mqjeff wrote:
Use reference variables instead of [x] values.


I agree with you to use 'x'. But if we use 'x', then we need to write loop for that condition. And it can be used for 2 values and more than that, it's better to use loop

Thanks & Regards
Android 23.


Well, I meant loop using a REFERENCE, rather than an integer.

And even without a loop, one should use a REFERENCE to point to specific points in the tree, at least for x= value > 1. Otherwise, the whole set of siblings is walked from 1 to x, and repeats this for each time x is accessed.
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
venkatachalam
PostPosted: Wed Jul 12, 2017 4:19 am Post subject: Reply with quote

Newbie

Joined: 24 Jun 2017
Posts: 3

Quote:
Hi All
I use loop with reference variable

Code:
DECLARE X INTEGER;
      DECLARE Y INTEGER 1;
      DECLARE M INTEGER;
      DECLARE N INTEGER 1;
      
      SET OutputRoot.JSON.Data.Item.DeviceSerialNo = InputRoot.XMLNSC.Item.DeviceSerialNo;
      SET OutputRoot.JSON.Data.Item.DeviceCategory = InputRoot.XMLNSC.Item.DeviceCategory;
      SET OutputRoot.JSON.Data.Item.DeviceDescription = InputRoot.XMLNSC.Item.DeviceDescription;
      SET OutputRoot.JSON.Data.Item.Manufacturer = InputRoot.XMLNSC.Item.Manufacturer;
      SET OutputRoot.JSON.Data.Item.ManufacturerYear = InputRoot.XMLNSC.Item.ManufacturerYear;
      SET OutputRoot.JSON.Data.Item.AMS = InputRoot.XMLNSC.Item.AMS;
      SET OutputRoot.JSON.Data.Item.AMCG = InputRoot.XMLNSC.Item.AMCG;
      SET OutputRoot.JSON.Data.Item.RegisterGroup = InputRoot.XMLNSC.Item.RegisterGroup;
      SET OutputRoot.JSON.Data.Item.AMIData = InputRoot.XMLNSC.Item.AMIData;
      SET OutputRoot.JSON.Data.Item.FunctionClass = InputRoot.XMLNSC.Item.FunctionClass;
      
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.InternalStatusNo = InputRoot.XMLNSC.Item.DeviceUserStatus.InternalStatusNo;
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.Status = InputRoot.XMLNSC.Item.DeviceUserStatus.Status;
      SET OutputRoot.JSON.Data.Item.DeviceUserStatus.DescriptionStatus = InputRoot.XMLNSC.Item.DeviceUserStatus.DescriptionStatus;
      
      CREATE FIELD OutputRoot.JSON.Data.Item.RegisterDetail IDENTITY(JSON.Array)RegisterDetail;
      DECLARE Reftoout REFERENCE TO OutputRoot.JSON.Data.Item.RegisterDetail;
      SET X = CARDINALITY(InputRoot.XMLNSC.Item.RegisterDetail[]);
      WHILE Y <= X DO
      SET Reftoout.RegisterDetail[Y].Register = InputRoot.XMLNSC.Item.RegisterDetail[Y].Register;
      SET Reftoout.RegisterDetail[Y].RegisterType = InputRoot.XMLNSC.Item.RegisterDetail[Y].RegisterType;
      SET Reftoout.RegisterDetail[Y].RegisterTypeText = InputRoot.XMLNSC.Item.RegisterDetail[Y].RegisterTypeText;
      SET Reftoout.RegisterDetail[Y].RegisterFactor = InputRoot.XMLNSC.Item.RegisterDetail[Y].RegisterFactor;
      SET Reftoout.RegisterDetail[Y].PredecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[Y].PredecimalPlaces;
      SET Reftoout.RegisterDetail[Y].DecimalPlaces = InputRoot.XMLNSC.Item.RegisterDetail[Y].DecimalPlaces;
      SET Reftoout.RegisterDetail[Y].TransformationRatio = InputRoot.XMLNSC.Item.RegisterDetail[Y].TransformationRatio;
      SET Reftoout.RegisterDetail[Y].PrimaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[Y].PrimaryVoltage;
      SET Reftoout.RegisterDetail[Y].SecondaryVoltage = InputRoot.XMLNSC.Item.RegisterDetail[Y].SecondaryVoltage;
      SET Reftoout.RegisterDetail[Y].PrimaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[Y].PrimaryCurrent;
      SET Reftoout.RegisterDetail[Y].SecondaryCurrent = InputRoot.XMLNSC.Item.RegisterDetail[Y].SecondaryCurrent;
      SET Reftoout.RegisterDetail[Y].UnitofMeasurement = InputRoot.XMLNSC.Item.RegisterDetail[Y].UnitofMeasurement;
      
      
       CREATE FIELD Reftoout.RegisterDetail[Y].ParentDevice IDENTITY(JSON.Array)ParentDevice;
       DECLARE Reftoouts REFERENCE TO Reftoout.RegisterDetail[Y].ParentDevice;
       SET M = CARDINALITY(InputRoot.XMLNSC.Item.RegisterDetail[Y].ParentDevice[]);
      WHILE  N <= M DO
      SET Reftoouts.ParentDevice[N].AllocationType = InputRoot.XMLNSC.Item.RegisterDetail[Y].ParentDevice[N].AllocationType;
      SET Reftoouts.ParentDevice[N].ControllingDevice = InputRoot.XMLNSC.Item.RegisterDetail[Y].ParentDevice[N].ControllingDevice;
      
      SET N= N+1;
      END WHILE;
      SET N = 1;
      
      SET Y = Y+1;
      END WHILE;


Last edited by venkatachalam on Wed Jul 12, 2017 4:35 am; edited 1 time in total
Back to top
View user's profile Send private message
timber
PostPosted: Wed Jul 12, 2017 4:33 am Post subject: Reply with quote

Yatiri

Joined: 25 Aug 2015
Posts: 654

Two comments:
1. The formatting is wrong in that post. Please use the 'Preview' button before clicking 'Submit'
2. I still see lots of indexes being used in your code. Good ESQL hardly ever uses an array index. You can always do the same thing using REFERENCE variables.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jul 12, 2017 4:37 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17384

timber wrote:
You can always do the same thing using REFERENCE variables.

Or a FOR statement..
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportHow to convert XML to JSON Array
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.