Certainly! Below is a formatted version of the README content for your GitHub repository, which includes the example usage of the json-to-df
package:
This repository provides a Common Lisp library to convert JSON data into a data frame using the json-to-df
package. The package leverages the yason
library for JSON parsing and dfio
for data frame operations.
-
Clone the repository into your Quicklisp local-projects directory:
git clone https://github.com/gassechen/json-to-data-frame.git ~/quicklisp/local-projects
-
Load the package in your REPL:
(ql:quickload :json-to-df)
-
Switch to the
json-to-df
package:(in-package :json-to-df)
(defparameter *url* "https://jsonplaceholder.typicode.com/posts")
(defun call-api (url-get)
(let* ((yason:*parse-json-booleans-as-symbols* t)
(yason:*parse-json-arrays-as-vectors* nil)
(respuesta
(yason:parse
(dex:get url-get
:keep-alive t
:use-connection-pool t
:connect-timeout 60
:want-stream t))))
respuesta))
(json-to-df (call-api *url*))
You will be prompted to select a symbol to be made accessible in the DFIO
package:
Select a symbol to be made accessible in package DFIO:
1. DATA-FRAME::BODY
2. DFIO::BODY
Enter an integer (between 1 and 2): 1
(lisp-stat:show-data-frames)
(json-to-df (call-api *url*) "my-df")
(lisp-stat:show-data-frames)
(df:print-data my-df)
The df:print-data
function will print the contents of the data frame my-df
:
JSON-TO-DF> (df:print-data my-df)
;; Output will display the data frame contents here
(defun get-from-url (url-get &optional (df-name "DF") (key nil))
;;with name df
JSON-TO-DF> (get-from-url "https://jsonplaceholder.typicode.com/users" "usersDF")
#<DATA-FRAME:DATA-FRAME (9 observations of 15 variables)>
;;with key
JSON-TO-DF> (get-from-url "https://www.swapi.tech/api/planets/" "planetsDF" "results")
#<DATA-FRAME:DATA-FRAME (9 observations of 3 variables)>
(defun get-from-file (file-path &optional (df-name "DF") (key nil))
JSON-TO-DF> (get-from-file "../tests/files/simpleobj.json" "filesimple")
#<DATA-FRAME:DATA-FRAME (2 observations of 3 variables)>
JSON-TO-DF> (get-from-file "../tests/files/multiplekesy.json" "multiplekey" "empleados")
#<DATA-FRAME:DATA-FRAME (1 observations of 8 variables)>
JSON-TO-DF> (asdf:test-system 'json-to-df)
JSON-TO-DF-SUITE: (Test Suite)
TEST-JSON-COMPLEXOBJ: E
TEST-JSON-SIMPLEOBJ:
TEST-JSON-MULTIPLEKEY:
TEST-JSON-NESTEDFILEANDARRAY:
TEST-JSON-NESTEDFILE:
TEST-JSON-SIMPLEFILE:
TEST-JSON-PLANETS:
TEST-JSON-COUNTRIES:
TEST-JSON-USERS:
TEST-JSON-PLACEHOLDER:
JSON-TO-DF-SUITE: (Test Suite)
TEST-JSON-COMPLEXOBJ: The value
(#<HASH-TABLE :TEST EQUAL :COUNT 3 {1015B12FB3}>) is not of type HASH-TABLE
Test functions:
Executed: 10
Skipped: 0
Tested 1 assertion.
Errors: 1/1 all tests had errors
T
This README provides a clear and concise guide on how to use the json-to-df
package to convert JSON data into a data frame and display it.