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 6210823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:13:44+00:00 2026-05-24T06:13:44+00:00

Is there any tool available that can convert a json file to a xml

  • 0

Is there any tool available that can convert a json file to a xml or csv file which can be opened in either of OpenOffice or Excel.

I am working on a web application and using MongoDB as backend. Have exported the data as json from MongoDB and need to convert the data in some format which can be opened by some spreadsheet software. I need to give this data to client and also slice-and-dice and decorate it before handing it over. I am planning to implement a feature which will export the required data in .csv and .xls format, but need a quick dirty solution now.

I had to do this same thing some time back also and found something(a simple script) which saved my day. Can’t locate the script again, any help would be very much appreciated.

UPDATE: Still looking for a solution and was trying to assemble a quick ruby script which can solve the problem. Anybody here knows which gem in rails adds to_xml to hash and array?

  • 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-05-24T06:13:45+00:00Added an answer on May 24, 2026 at 6:13 am

    I tried to convert the json to xml with following code in rails console:

    arr = []
    File.readlines("some_name.json").each {|l| arr << JSON.parse(l)}
    File.open("some_name.xml", "w").write(arr.to_xml)
    

    But the json had some keys with “$” in them, and Excel refused to open the xml file. So I tried again with this in the console:

    class Array
      def sanitize_for_xml
        self.each{|entry| entry.sanitize_for_xml if entry.respond_to?(:sanitize_for_xml)}
        self
      end
    end
    
    class Hash
      def sanitize_for_xml
        self.each do |key, value|
          self[key] = value.sanitize_for_xml if value.respond_to?(:sanitize_for_xml)
        end
    
        self.keys.each do |key|
          self[key.gsub(/\W/, "")] = self.delete(key)
        end
        self
      end
    end
    
    arr = []
    File.readlines("galgotias.2010-08-02.json").each {|l| arr << JSON.parse(l)}
    arr.sanitize_for_xml
    File.open("galgotias.2010-08-02.xml", "w").write(arr.to_xml)
    

    And was able to open generated xml in Excel, although it was not a neat excel and I spent a lot of time slicing and dicing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way or tool available that can profile AS3 code without using
Is there any tool available by which one can calculate the size or a
Is there any tool that can parse a valid C program and generate a
Is there any tool that lists which and when some classes are effectively used
Is there any tool available that takes C code as input and outputs valid
Does Kdiff3 have APIs available? Or is there any comparison tool's API available that
Hi is there any tool available in Java world that will parse/read a source
Is there any (free) tool available that is able to produce a graph showing
Is there any free tool available for creating and editing PNG Images?
Is there any code coverage tool available for PHP? I wish to check 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.