# CSL as JSON?

**URL:** https://discourse.citationstyles.org/t/csl-as-json/977
**Category:** CSL Development
**Created:** [March 12, 2011, 9:47pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977 "2011-03-12T21:47:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bruce\_D\_Arcus1](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@Bruce\_D\_Arcus1](https://discourse.citationstyles.org/u/Bruce_D_Arcus1)
#### Post date: [March 12, 2011, 9:47pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977/1 "2011-03-12T21:47:50Z")

</div>

I wonder: is there any value in using a JSON representation of CSL  
styles for certain processing circumstances?

I’m thinking about the fact that:

1. XML is kind of a pita in the javascript world (namely, support is  
inconsistent)
2. the CSL editor code has to convert back-and-forth to a JSON representation?

Here’s a gist with a simple Ruby script to convert the style, and the  
result using APA.

[https://gist.github.com/867583](https://gist.github.com/867583)

Bruce

---

<div class="post-metadata">

### Author: ![Bruce\_D\_Arcus1](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@Bruce\_D\_Arcus1](https://discourse.citationstyles.org/u/Bruce_D_Arcus1)
#### Post date: [March 13, 2011, 7:59pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977/2 "2011-03-13T19:59:15Z")

</div>

And related …

I guess while I’m at it and frustrated with inconsistent namespace  
support in different XML tools\*, what are the trade-offs in dropping  
use of a namespace?

The namespace was kind of necessary in the all XML workflow CSL began  
in, and we now have legacy issues that make contemplating these sorts  
of changes painful, but I don’t think it’s necessary in 2011, and it  
would make things easier in some ways.

Bruce

- For example, as far as I can tell, the REXML library in the Ruby  
standard library still doesn’t do this right, despite the fact that I  
reported a bug (IIRC) years ago.

---

<div class="post-metadata">

### Author: ![Simon\_Kornblith](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Simon\_Kornblith](https://discourse.citationstyles.org/u/Simon_Kornblith)
#### Post date: [March 13, 2011, 9:06pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977/3 "2011-03-13T21:06:43Z")

</div>

I may be wrong, but it seems to me that any XML parsing library that doesn’t support namespaces is useless for parsing virtually any standards-based format, since they all use namespaces.

Simon

---

<div class="post-metadata">

### Author: ![Simon\_Kornblith](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Simon\_Kornblith](https://discourse.citationstyles.org/u/Simon_Kornblith)
#### Post date: [March 13, 2011, 9:34pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977/4 "2011-03-13T21:34:01Z")

</div>

I’m not sure whether either of these is really be a big deal. Browser support for XML is not all that bad. Modern browsers (Firefox, Chrome, Safari, Opera, IE 9) support DOMParser and XMLHttpRequest, and older versions of IE can be made to support both of these with \<10 lines of code. I’m also not sure that XML parsing is really a performance bottleneck. CSL styles are generally pretty small relative to e.g. a webpage, so there isn’t much data to parse. I don’t know what the overhead is for DOM XML/E4X API calls, but I assume it’s not too big, and this is something we could profile.

If we did want to convert to JSON, I think we’d need a different representation than what you have here, as it seems like you’ve realized, but I’m not convinced this is worth the effort.

Simon

---

<div class="post-metadata">

### Author: ![Bruce\_D\_Arcus1](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@Bruce\_D\_Arcus1](https://discourse.citationstyles.org/u/Bruce_D_Arcus1)
#### Post date: [March 13, 2011, 9:57pm UTC](https://discourse.citationstyles.org/t/csl-as-json/977/5 "2011-03-13T21:57:30Z")

</div>

> > I wonder: is there any value in using a JSON representation of CSL  
> > styles for certain processing circumstances?
> > 
> > I’m thinking about the fact that:
> > 
> > 1. XML is kind of a pita in the javascript world (namely, support is  
> > inconsistent)
> > 2. the CSL editor code has to convert back-and-forth to a JSON representation?
> 
> I’m not sure whether either of these is really be a big deal.

Fair enough.

> I may be wrong, but it seems to me that any XML parsing library that doesn’t support namespaces is useless for parsing virtually any standards-based format, since they all use namespaces.

Yeah, but they don’t all do it correctly. But maybe libraries in that  
category are more of a minority than I was worrying about.

Bruce
