cancel
Showing results for 
Search instead for 
Did you mean: 

Convert XML to Json format - jScript

Highlighted
Frequent Contributor

Convert XML to Json format - jScript

Hey guys, I curretly have an XML file that I use to map some test data so I could create another XML file and send it somwhere.
 
Current XML format is:
 
<Mappings>
<Test id="Test_1000_test">
    <TestIdMapping>Test_1001_test1</TestIdMapping>
     <TestIdMapping>Test_1002_test2</TestIdMapping>
</Test>
<Test id="Test_2000_test">
    <TestIdMapping>Test_2001_test1</TestIdMapping>
     <TestIdMapping>Test_2002_test2</TestIdMapping>
  <TestIdMapping>Test_2003_test3</TestIdMapping>
</Test>
<Mappings>
 
Basically I am mapping 1001, 1002 to 1000.......
I would like to switch this file to JSON and have it in TestComplete instead of reading it from the outside (external XML).
What's is the best way to it ? I have an idea in head but I would like your opinion.
Please note that file could have up to few hundreds tests. 
 
 
Tags (3)
5 REPLIES 5
Highlighted
Frequent Contributor

Re: Convert XML to Json format - jScript

Any help on this one for the best scenario ?
Highlighted
Community Hero

Re: Convert XML to Json format - jScript

Hi,

 

I am not sure I got the problem... Could you elaborate it with more details?

What is the problem with replacing XML with JSON? (Obviously parser must be replaced as well.)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Frequent Contributor

Re: Convert XML to Json format - jScript

How do I form a JSON object to follow the same design as the XML and read it ? First time using JSON 🙂 believe it or not. 

 

Basically I need to FIND the Test_1000_test and once I find it I need to push all tests under that one  into an array, so my array would be array = [1001,1002]

Highlighted
Frequent Contributor

Re: Convert XML to Json format - jScript

Awaiting on someone's help when you get a chance.
Highlighted
Frequent Contributor

Re: Convert XML to Json format - jScript

Here is the JSON I got, I converted my XML to JSON......should I still save it as jason.js in test complete ?

 

{
"Mappings": {
"Test": [
{
"-id": "Test_1000_test",
"TestIdMapping": [
"Test_1001_test1",
"Test_1002_test2"
]
},
{
"-id": "Test_2000_test",
"TestIdMapping": [
"Test_2001_test1",
"Test_2002_test2",
"Test_2003_test3"
]
}
]
}
}

 

Now, How could I read look for id = Test_1000_test and once found, I loop into the childs and push them into an array ?

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors