tags:

views:

721

answers:

3

How might you take JSON output (e.g., from http://www.kinggary.com/tools/todoist-export.php) and strip the names to yield just the values from each pair, as CSV or human-friendly text? Want a more readable, human-editable backup of my friend's data on todoist.com

A: 

Can you JSON decode it to an array and just iterate the array for values? A sample of the JSON output would be helpful.

Myles
+1  A: 

Your example site generates XML for me, not JSON. In either case I'd probably reach for Ruby:

require 'net/http'
require 'rexml/document'

xml = Net::HTTP.get_response(URI.parse("http://www.kinggary.com/tools/todoist-export.php?completed=incomplete&retrieval=view&submit=Submit&process=true&key=MYKEY")).body

data = REXML::Document.new(xml)

data.elements.each('//task/content') do |e| 
  puts e.text 
end
Jim Zajkowski
Jim, thanks for the fast, focused response. I'd carelessly assumed JSON since that's what the todoist API returns. Do you know if there's an easy-setup Ruby environment I could install on Windows to try this?
Paul
Jim Zajkowski
Sweet! It works (once I tried SciTE instead of fxri), and I got it writing to a text file. Thanks again.
Paul
A: 

What language? PHP has a json_decode() function that turns the JSON into an object or associative array. You could then loop through the array or get the values from the object to turn it into whatever format you like.

Jergason