How to Convert Markdown to JSON?

Viewed 10048

I need help with something.I need to convert the Markdown file to json format, but I don't know how to do this.I did a Google search, "markdown to json" but the tools I used didn't work for me.Is there someone who has experienced this before?

PS: I can use Nodejs and python for this.But I used the nodejs and python modules related to this did not work.

example Markdown

```{python}
from __future__ import division
from deltasigma import *
```

### 5th-order modulator: NTF *with* zeros optimization

This time we enable the zeros optimization, setting `opt=1` when calling synthesizeNTF(), then replot the NTF as above.

* 0 -> not optimized,
* 1 -> optimized,
* 2 -> optimized with at least one zero at band-center,
* 3 -> optimized zeros (with optimizer)
* 4 -> same as 3, but with at least one zero at band-center
* [z] -> zero locations in complex form

I would like this or similar json output

{
    code:
    header :
    content :
}

In fact, as long as code and other content blogs are separated, there is no problem.

In addition to the above, I can even write my own converter with nodejs, but it can take a very long time. Thanks in advance

2 Answers

There is a very straightforward approach incase you are working on rasa.

import rasa_nlu
from rasa_nlu.training_data import load_data

input_training_file_md_file = "nlu_data.md"


output_json_file = 'nlu_data.json'

with open(output_json_file,'w') as f:
    f.write(load_data(input_training_file_md_file).as_json())
#done

You mentioned you Google'd this, so I'm sure you saw this, but for a working example of this in python, check out: https://github.com/njvack/markdown-to-json

Beyond that, I recommend reading the README for the project on some things you're going to run into. Ultimately, they're not the same type of format, so the conversion isn't reversible without guess work. Notice how all of the packages are a variety of responses. They're inventing a JSON key-value response structure to make things semi understandable.

If existing tools don't do what you need, try checking out what they're doing, and change it to your needs.

Related