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
2009-11-14 20:26:46
+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
2009-11-14 20:33:19
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
2009-11-14 22:51:18
Jim Zajkowski
2009-11-15 00:18:23
Sweet! It works (once I tried SciTE instead of fxri), and I got it writing to a text file. Thanks again.
Paul
2009-11-17 03:21:12
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
2009-11-14 20:34:07