Skip to main content
Ground Control | Tier 1
August 20, 2022
Solved

how convert xml to json

  • August 20, 2022
  • 3 replies
  • 185 views
how convert xml to json
    Best answer by yssf

    I'm thinking of a couple ways to achieve this:

    1. XML package > Dictionary package > JSON package
    2. Python package
    3. JavaScript package
    4. Use one of the XML to JSON packages in the Bot Store.

    If you're comfortable with coding you could choose option 2 or 3. If you're in a hurry you can go for option 4.

    Otherwise option 1 to learn the most. Loop through your XML file with the Loop action. Then For each Node in a XML Dataset get the XML node (“key”) with XML: Get single node action using the correct XPath expression and assign the output to a string variable. For the XML value use the same XML: Get single node action with another XPath expression and assign the output to a string variable.

    After checking you have the correct XML nodes (as keys) and corresponding XML values create a Dictionary variable and use the Dictionary: Put action from the Dictionary package to assign the earlier retrieved XML nodes (keys) variable and XML values variable iteratively.

    Lastly, use the Convert Dictionary to JSON action from the Json package to convert the populated Dictionary variable to JSON.

    3 replies

    Automation Anywhere Team
    September 23, 2022

    Hi @Ahmed Ghanem​ ,

     

    Good Day!

     

    Please let me know you are looking for a package to convert XML to json.

     

    Thank you

    Automation Anywhere Team
    January 17, 2025

    YEs

     

    yssfAnswer
    Cadet | Tier 2
    January 17, 2025

    I'm thinking of a couple ways to achieve this:

    1. XML package > Dictionary package > JSON package
    2. Python package
    3. JavaScript package
    4. Use one of the XML to JSON packages in the Bot Store.

    If you're comfortable with coding you could choose option 2 or 3. If you're in a hurry you can go for option 4.

    Otherwise option 1 to learn the most. Loop through your XML file with the Loop action. Then For each Node in a XML Dataset get the XML node (“key”) with XML: Get single node action using the correct XPath expression and assign the output to a string variable. For the XML value use the same XML: Get single node action with another XPath expression and assign the output to a string variable.

    After checking you have the correct XML nodes (as keys) and corresponding XML values create a Dictionary variable and use the Dictionary: Put action from the Dictionary package to assign the earlier retrieved XML nodes (keys) variable and XML values variable iteratively.

    Lastly, use the Convert Dictionary to JSON action from the Json package to convert the populated Dictionary variable to JSON.