I want to insert lots of JSON data into my db.
[{
"term": "wine",
"name": "Bubba Wine & Spirits",
"address": "1234 N San Fake Rd,"
}, {
"term": "wine",
"name": "Wine Shop",
"address": "123 N Not Real Blvd,"
}]
I use cl-json to convert to lisp objects.
(defvar *data*
(decode-json (open "my-json-file.json")))
Results look like:
(((:TERM . "wine") (:NAME . "Bubba Wine & Spirits")
(:ADDRESS . "1234 N San Fake Rd,"))
((:TERM . "wine") (:NAME . "Wine Shop")
(:ADDRESS . "123 N Not Real Blvd,")))
Postmodern lists one way to insert multiple rows with insert-rows-into here: https://sites.google.com/site/sabraonthehill/postmodern-examples/postmodern-insert#multiple-row-inserts
(:insert-rows-into 'table :columns 'a 'b :values '((10 20) (30 40)))
It's not quite the default JSON format.
It looks like I have two options:
- Massage the data to fit
- Find a function that takes it as is.
I suspect :insert-rows-into does what I want but I'm not quite sure how to cram it in there.