Skip to content

Getting just the json from editor.get() #314

Closed Answered by josdejong
RyanAlexanderSingh asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the utility function toJSONContent(content).json to get the contents as a JSON object. Note that this function can throw an exception when the contents of the editor are no valid JSON (for example when the user is halfway typing in text mode, or the document is empty).

You can also write your own utility function:

function contentToJSON(content) {
  return content.json !== undefined 
    ? content.json 
    : JSON.parse(content.text) // Note: can throw an error
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by RyanAlexanderSingh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants