question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON parsing error for rendered output

See original GitHub issue

I’m having trouble using citation.js to convert CSL JSON to rendered citations. Converting to bibtex works as expected.

Based on https://runkit.com/larsgw/591b5651bd9b40001113931c, I get the following results:

const Cite = require("citation-js")

const data = new Cite([{"id":78,"type":"article-journal","title":"Identification of Positive Regulators of the Yeast Fps1 Glycerol Channel","container-title":"PLoS Genet","page":"e1000738","volume":"5","issue":"11","source":"PLoS Genet","journalAbbreviation":"PLoS Genet","author":[{"family":"Beese","given":"Sara E."},{"family":"Negishi","given":"Takahiro"},{"family":"Levin","given":"David E."}]}])

data.get({
  type: 'html',
  style: 'bibtex'
})

gives

@article{BeeseIdentification,

    author={Sara E. Beese and Takahiro Negishi and David E. Levin},
    journal={PLoS Genet},
    issue=11,
    pages={e1000738},
    title={{Identification of Positive Regulators of the Yeast Fps1 Glycerol Channel}},
    volume=5,

}

In contrast,

const Cite = require("citation-js")

const data = new Cite([{"id":78,"type":"article-journal","title":"Identification of Positive Regulators of the Yeast Fps1 Glycerol Channel","container-title":"PLoS Genet","page":"e1000738","volume":"5","issue":"11","source":"PLoS Genet","journalAbbreviation":"PLoS Genet","author":[{"family":"Beese","given":"Sara E."},{"family":"Negishi","given":"Takahiro"},{"family":"Levin","given":"David E."}]}])

data.get({
  type: 'html',
  style: 'citation-apa'
})

gives the error

SyntaxError: Unexpected token u in JSON at position 0

(see https://runkit.com/5af4a2c58a83410012ddbf47/5af4a2d65bba2900126994f2#)

If I use new Cite('Q21972834') instead of using raw CSL-JSON as input both work. Any idea what’s going on here?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
larsgwcommented, May 11, 2018

Here’s a demo on how to use the RIS output BTW: https://runkit.com/larsgw/citation.js-ris-output-demo

Basically this:

Cite(...).get({
  format: 'string',
  type: 'string',
  style: 'ris'
})

Or, with the new API:

Cite(...).format('ris')

Additionally, you can pass parameters:

Cite(...).format('ris', {
  type: 'text' // alternative: 'object' gives you an object representation
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Error when trying to use output of Parse JSON
I used the payload to create the schema and the parse runs fine, rendering all the data into the proper variable names. I...
Read more >
Getting error parsing and displaying JSON object in ReactJS
Here is the code as it is: import React, { Component } from 'react'; class WhoIs extends Component { render() { var origObject...
Read more >
How to handle invalid JSON parse error properly.
The most common way to handle JSON parse error is using try-catch block. If the JSON string is valid, it will return a...
Read more >
BEE Plugin Tech Docs | JSON Parser errors
1 : In case of a Bump error, the JSON parser forwards to the user the error ... 4602, Rendering error, 403 Forbidden,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found