1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2015, 2016 Eric Bavier <bavier@member.fsf.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix import json)
22 #:use-module (guix http-client)
23 #:use-module (guix import utils)
24 #:use-module (srfi srfi-34)
25 #:export (json-fetch))
27 (define (json-fetch url)
28 "Return an alist representation of the JSON resource URL, or #f on failure."
29 (guard (c ((and (http-get-error? c)
30 (= 404 (http-get-error-code c)))
31 #f)) ;"expected" if package is unknown
32 (let* ((port (http-fetch url #:headers '((user-agent . "GNU Guile")
33 (Accept . "application/json"))))
34 (result (hash-table->alist (json->scm port))))