Forum Discussion

fazlook's avatar
fazlook
Frequent Contributor
4 years ago

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. 
 
 

11 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.)

     

    • fazlook's avatar
      fazlook
      Frequent Contributor

      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]

      • fazlook's avatar
        fazlook
        Frequent Contributor
        Awaiting on someone's help when you get a chance.
  • fazlook's avatar
    fazlook
    Frequent Contributor
    Any help on this one for the best scenario ?
    • fazlook's avatar
      fazlook
      Frequent Contributor

      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 ?