CSL Json Export
Hi there,
Is there anyway to edit the CSL Json export file so as to get my Zotero tags in there?
I'm using the Json file from my Zotero database (+2000 entries) as a feed for an online dataTables render. I would like to just export the file to an FTP and have the database update.
Is there anyway to edit the CSL Json export file so as to get my Zotero tags in there?
I'm using the Json file from my Zotero database (+2000 entries) as a feed for an online dataTables render. I would like to just export the file to an FTP and have the database update.
doExport function: https://github.com/zotero/translators/blob/master/CSL JSON.js#L68
You already have the item (which contains item.tags) and you have the CSL JSON created by ZU.itemToCSLJSON(item), so you'd just need to add the tags into the JSON in the format you'd like (likely an array?) before pushing the item to the data array.
We can see if we'd want to modify the itemToCSLJSON function more generally -- that's my question above -- but a) that's going to take longer and b) it'd almost certainly include the tags as a (comma or semicolon delimited) string, which isn't ideal.
function doExport() {
var item, data = [];
while(item = Z.nextItem()) {
var itemJSON = ZU.itemToCSLJSON(item);
itemJSON = itemJSON.push(item.tags);
data.push(itemJSON);
}
Z.write(JSON.stringify(data, null, "\t"));
}
function doExport() {
var item, data = [];
while(item = Z.nextItem()) {
var itemJSON = ZU.itemToCSLJSON(item);
itemJSON.keyword = item.tags.join(", ");
data.push(itemJSON);
}
Z.write(JSON.stringify(data, null, "\t"));
}
itemJSON.keyword = item.tags.map(o => o.tag).join(", ");
The use for this ability is as follows: A friend of mine put together a nice little TypeScript script which loads a JSON list of exported Zotero items in a webpage and turns its tags into buttons (https://github.com/henriksen/bookie). When clicked, the buttons display a list of sources with URLs linking to the titles.
This was created for the purpose of sharing large lists of open access historical books/documents that are often available on archive.org. See an example here: https://froginawell.net/frog/primary-sources-the-malay-world/#books
Yesterday, I discover that at some point the modified JSON export with Tags translator, using one of the methods from above was broken. I believe this may have been due to some kind of change in the way translators are done. I was also not able to get things up and running with BBT as an alternative. Nor was david_lindemann's link above working for me anymore.
I ended up updating the modified script to bring in changed code in the latest CSL JSON.js I could find, and it seems to be functioning again after fiddling with the doExport() function again. Sharing the modified translator below in case a) this is useful to anyone else or b) this is not a good way to go about it, in which case, happy to accept suggestions for alternatives. For now, happy it is up and working again.
Any reason why JSON export can't include tags by default? Something to do with CSL standards?
CSL JSON with tags:
https://gist.github.com/kmlawson/0f3eb75f462bca340897a4d1daf2c708
BBT does support various JSON export formats, though, and @emilianoeheyns might have suggestions of which to use?
I was just here to report a *solution* for benefit of others, it was not to report a problem! :-)
CSL JSON saves dates differently than BBT, has “author” instead of “creators” etc., all of this is fine and perhaps better, but it just means it won’t work out of box for me with Bookie code written back in 2021 by someone else and it is far easier for an amateur like me to mess with one thing than several!
Thanks again to everyone: repeat - nothing to see here unless you are interested in my very one-off special solution! I was just trying to be helpful.
If you want JSON and you want tags with your JSON you can add a single translator like the one above, or you can install the large, powerful, and useful collection of the tools of bbt, which adds a bit of time to every launch of the Zotero app (but worth it for what it offers).
Whatever works for you!
"CSL JSON saves dates differently than BBT", if that means ""CSL JSON saves dates differently than BBT CSL JSON", means that one of them is off-standard, as the way dates are represented in CSL JSON is fixed. They can't be structurally different and both be valid, and if BBT CSL JSON is out of spec, I'd love to fix that.
Thanks, glad you understood what was going on. I wish you luck in your debugging!
Here is CSL JSON example:
https://pastebin.com/UMVL9SYs
Here is BetterBitTeX JSON example:
https://pastebin.com/V1dG3nku
That includes tags (the topic of this forum thread) but, as I mentioned above, does not work with the Bookie code unmodified because of differences with this format without further work.
Here is an example with your Better CSL JSON:
https://pastebin.com/ugXGQuQh
Which is not helpful here since it doesn't include tags (defeating the purpose of using BBT). This is why this is not the export format I'm referring to as it offers no advantage over the original. You have a post above with something to do with postscripts, which looks like an interesting alternative solution but not one that was explained here and I couldn't make much sense of the github thread or the documentation pages for this.
The absolute simplest solution for my specific need was to duplicate and modify the translator again and add
if (item.tags) {
cslItem.tags = item.tags;
}
That saves me messing with Bookie. That is pretty much the modification to that file I linked above.
Thanks so much for your hard work on BetterBibTex - a wonderful resource.
And BBT json is absolutely not the only format to export tags (RDF does too for example).