From 517837b3a167bf365be71186d13615f4f0c49dcf Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 27 Jun 2010 15:50:07 -0700 Subject: [PATCH] library of babel: added json function for accessing local or remote json objects A quick example of accessing remote json data from Babel code blocks. Evaluate the following to see a listing of parks in DC by ward. #+source: dc-parks #+begin_src emacs-lisp :var keys='(ward address) :var data=json(url="http://ogdi.cloudapp.net/v1/dc/RecreationParks?format=json") (append (list keys 'hline) (mapcar (lambda (lis) (mapcar (lambda (key) (cdr (assoc key lis))) keys)) (cdr (car data)))) #+end_src --- contrib/babel/library-of-babel.org | 37 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org index 807ada4d9..330734440 100644 --- a/contrib/babel/library-of-babel.org +++ b/contrib/babel/library-of-babel.org @@ -1,22 +1,6 @@ #+title: The Library of Babel -#+SEQ_TODO: TODO PROPOSED | DONE DEFERRED REJECTED -#+OPTIONS: H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc +#+author: Org-mode People #+STARTUP: odd hideblocks -#+STYLE: - -#+begin_html - -#+end_html * Introduction The Library of Babel is an extensible collection of ready-made and @@ -69,6 +53,25 @@ as a table in traditional Org-mode table syntax. nil #+end_src +** remote files + +Read local or remote file in [[http://www.json.org/][json]] format into emacs-lisp objects. +#+srcname: json +#+begin_src emacs-lisp :var file='() :var url='() + (require 'json) + (cond + (file + (with-temp-filebuffer file + (goto-char (point-min)) + (json-read))) + (url + (require 'w3m) + (with-temp-buffer + (w3m-retrieve url) + (goto-char (point-min)) + (json-read)))) +#+end_src + * Plotting code ** R