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.
  • @Rintze @fbennett CSL does have a keyword variable, so we could do this legally. It's not used in any style, afaik, so it wouldn't break anything. Any objections/thoughts? Frank, citeproc-js just expects a string there, I assume?
  • FYI: at the moment I'm using the XML export, which I edited (the "Endnotes xml" file), and then I'm converting to JSON. I would like to skip this middle step.
  • I think to customize this, you should be able to hook into the
    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.
  • I think I understood the gist of it, but the truth is I have no idea how to code js to get that done.
  • I'd have to test this myself, but my starting point would be something like
    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"));
    }
  • This doesn't work. There's a javascript error during the CSL Json output.
  • yeah, as I said, it was untested code, more designed as an outline than working code. I'm not going to have time to debug this, sorry. We can see what people say about putting the functionality in the upstream function.
  • Yeah, I understand. But let me tell you, javascript/jquery datatables fed by Json arrays are very useful at the moment, and I think it would really benefit Zotero to work in tandem with them with a simple (but thorough) export. My implementation already works rather well but tags would be useful in order to have simple category filters (or other kinds of metadata tricks).
  • Completely agree. We're working on a full JSON export in JSON-LD format based (mostly or entirely) on schema.org. No ETA, but hopefully going to happen first half of this year.
  • Try this code instead (not tested):
    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"));
    }
  • It partly works! But it returns [object Object].
  • itemJSON.keyword = item.tags.map(o => o.tag).join(", ");
  • That is perfect, my friend. Thank you very much!
  • CSL does have a keyword variable, ..., citeproc-js just expects a string there, I assume?
    Yes. See https://github.com/citation-style-language/schema/blob/v1.0.1/csl-data.json#L350

  • edited January 17, 2021
    Here is a version of the CSL JSON translator that exports attachments, notes, tags, and "extra": https://github.com/dlindem/zotero_lexbib_rdf/blob/af0379536a0fec316df62ceb2ab745e650b95f90/zotero/LexBib JSON.js#L109
  • These things can also be done with BBT CSL JSON, with a postscript. Adding attachments by default was discussed here, where it was suggested that someone pitch the idea on xbiblio-devel. If it would get agreement there, I see no issue in adding it to BBT CSL JSON exports.
Sign In or Register to comment.