Ionică Bizău

Web Developer, Linux geek and Musician

How to convert JSON to Markdown using json2md

I love and use both JSON and Markdown in my projects. Each npm package requires a package.json file which is obviously written in JSON format. Also, good projects have good documentation. My favorite language for writing docs is Markdown.


But I don't really write Markdown files. I do write docs, but they are stored in the code (JSDoc comments). I automated the process of generating Markdown docs using Blah. However, sometimes these documentation templates are not enough.

That's why I created json2md which is the bridge between JSON and Markdown languages. Integrating this package with my Blah templates, I can write custom things in the final documentation result using JSON inputs in my package.json (or another JSON file).

How to use

Everything starts with a npm i json2md to download and install the json2md package locally. Then you can require it in your Node.js apps or even on the client-side (in the browser).

For example, to create a Markdown image result, you have to do this:

var json2md = require("json2md");

var myImg = json2md({
    img: {
        source: ""
      , title: "My image"

This will output ![My image](

Here is another example which is more complex:

// Dependencies
var json2md = require("json2md");

    { h1: "JSON To Markdown" }
  , { blockquote: "A JSON to Markdown converter." }
  , { img: [
        { title: "Some image", source: "" }
      , { title: "Another image", source: "" }
      , { title: "Yet another image", source: "" }
  , { h2: "Features" }
  , { ul: [
        "Easy to use"
      , "You can programatically generate Markdown content"
      , "..."
  , { h2: "How to contribute" }
  , { ol: [
        "Fork the project"
      , "Create your branch"
      , "Raise a pull request"

This will generate:

# JSON To Markdown
> A JSON to Markdown converter.

![Some image](

![Another image](

![Yet another image](

## Features

 - Easy to use
 - You can programatically generate Markdown content
 - ...

## How to contribute

 1. Fork the project
 2. Create your branch
 3. Raise a pull request

And this is not all! You can create your custom converters. Let's suppose you have an input like { sayHello: "World" }. If you want to generate a Hello World! output, you can do:

json2md.converters.sayHello = function (input) {
     return "Hello " + input "!";

This basically extends the converters object and adds your custom converter. :dizzy:

Check out json2md on GitHub. I'm sure there are a lot of things to improve. Feel free to ask questions, open issues and contribute! :sparkles:

Read more »

7 of My Favorite Bible Passages

Bible is full of beautiful verses that encourage us and light our path in this world. While they all are important, I have some favorite passages that I like in special. Here are seven of them. :dizzy:


John 3.16

For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.

Thanks to Jesus, we have the chance to have eternal life and be forever with our heavenly Father.

John 14:6

Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. If you really know me, you will know my Father as well. From now on, you do know him and have seen him.”

According to this verse, the only way to get the salvation from sin is Jesus–the truth and the life. There is no other way.

2 Peter 3:9-13

The Lord is not slow in keeping his promise, as some understand slowness. Instead he is patient with you, not wanting anyone to perish, but everyone to come to repentance.

But the day of the Lord will come like a thief. The heavens will disappear with a roar; the elements will be destroyed by fire, and the earth and everything done in it will be laid bare.

Since everything will be destroyed in this way, what kind of people ought you to be? You ought to live holy and godly lives as you look forward to the day of God and speed its coming. That day will bring about the destruction of the heavens by fire, and the elements will melt in the heat.

But in keeping with his promise we are looking forward to a new heaven and a new earth, where righteousness dwells.

This world we know is not our home. Believing God's promise, we're waiting a new heaven and a new earth where shall be no more death, nor sorrow, nor crying (Revelation 21:4).

Genesis 2:29

Then God said, “I give you every seed-bearing plant on the face of the whole earth and every tree that has fruit with seed in it. They will be yours for food.

This is one of the reasons why I am vegetarian. :green_apple: Humans were not designed to eat meat, but vegetables. And by the way, on the new earth nobody will eat meat (even the animals will not eat each others, see Isaiah 65:25). :leaves: :grapes:

Revelation 22:12

“Look, I am coming soon! My reward is with me, and I will give to each person according to what they have done. I am the Alpha and the Omega, the First and the Last, the Beginning and the End.

Jesus is coming soon, yes, He's coming! :sparkles:

Malachi 4:1-3

Surely the day is coming; it will burn like a furnace. All the arrogant and every evildoer will be stubble, and the day that is coming will set them on fire,” says the Lord Almighty. “Not a root or a branch will be left to them.

But for you who revere my name, the sun of righteousness will rise with healing in its rays. And you will go out and frolic like well-fed calves.

Then you will trample on the wicked; they will be ashes under the soles of your feet on the day when I act,” says the Lord Almighty.

There will come a day, a day of victory, when the sin will disappear and all the things will be new. :high_brightness:

Psalm 119:105

Your word is a lamp to my feet
And a light to my path.

May God help us to accept His word as light in the darkness of this world! :flashlight:

Read more »

Uploading videos to YouTube using NodeJS

Using different service APIs may be difficult, especially for beginners, but not only. In this post, I will try to make clearer how to upload a video on YouTube, using NodeJS.

Back in 2013 I published my first NPM module: youtube-api–an object-oriented wrapper for the YouTube v3 API. People liked this module and the feedback came. Contributions, bug reports, stars etc. That means people actually used my module which is incredible. :dizzy:

So, let's suppose you have a video file (codename: video.mp4) and you want to upload it on your YouTube account. While there are a couple of authenticating methods (JWT, OAuth2, Server Key etc), to upload videos on YouTube, you need OAuth2 authentication.

The documentation cleary states:

Service accounts do not work for YouTube Data API calls because service accounts require an associated YouTube channel, and you cannot associate new or existing channels with service accounts. If you use a service account to call the YouTube Data API, the API server returns an error with the error type set to unauthorized and the reason set to youtubeSignupRequired.

So, we need OAuth2 authentication. If you are not familiar with OAuth2, you may need to read the docs.

Creating a Google application

Like for other API services, you need to create an application which will be the bridge between you and the API service. To access the YouTube resources, you need to create a Google application.

  1. Open your Google console and create the project by clicking the Create Project button.

  2. Set the project name in the popup that was opened.

  3. After the application is created, go to APIs & auth and click the APIs menu item.

  4. Here you have to enable the YouTube Data API. For that, click the YouTube Data API link and then click the Enable API button.

  5. Before getting the credentials, you have to set the Consent screen information (the product name is mandatory):

  6. Now it's the time to get the application credentials. But there are no credentials yet. You have to create the OAuth2 Client ID. To do that, go to Credentials page and click Create new Client ID. A popup will be opened.

  7. Set the Authorized JavaScript origins–just put http://localhost:5000 because there will run our local server (you may add other origins like development and production urls). The callback url is http://localhost:5000/oauth2callback–after allowing the application to access your account (YouTube resources in this case), you will be redirected there.

  8. After clicking the Create Client ID button, you will get your credentials.

  9. Now click the Download JSON button to download the credentials in JSON format.

Since you have the credentials on your computer, we can now start coding our script. :grinning:

Using youtube-api to upload the video

We will set up a lien server which will handle the OAuth2 callback url.

See the inline comments. It's easier to understand the things.

// YouTube will handle the YouTube API requests
var Youtube = require("youtube-api")

    // We will use `fs` to read the video file
  , Fs = require("fs")

    // `r-json` will read the JSON file (credentials)
  , ReadJson = require("r-json")

    // `lien` handles the server requests (localhost:5000)
  , Lien = require("lien")

    // Logging things
  , Logger = require("bug-killer")

    // Open in the default browser
  , Opn = require("opn")

// Copy the downloaded JSON file in `credentials.json`
const CREDENTIALS = ReadJson("./credentials.json")
      // Set the video path (it can be any video file)
    , VIDEO_PATH = "video.mp4"

// Init the lien server
var server = new Lien({
    host: "localhost"
  , port: 5000

// Authenticate using the credentials
var oauth = Youtube.authenticate({
    type: "oauth"
  , client_id: CREDENTIALS.web.client_id
  , client_secret: CREDENTIALS.web.client_secret
  , redirect_url: CREDENTIALS.web.redirect_uris[0]

// Open the authentication url in the default browser
    access_type: "offline"
  , scope: [""]

// Here we're waiting for the OAuth2 redirect containing the auth code"/oauth2callback", function (lien) {
    Logger.log("Trying to get the token using the following code: " +;

    // Get the access token
    oauth.getToken(, function(err, tokens) {
        if (err) { lien.end(err, 400); return Logger.log(err); }

        // Set the credentials

        // And finally upload the video! Yay!
            resource: {
                // Video title and description
                snippet: {
                    title: "Testing YoutTube API NodeJS module"
                  , description: "Test video upload via YouTube API"
                // I don't want to spam my subscribers
              , status: {
                    privacyStatus: "private"
            // This is for the callback function
          , part: "snippet,status"

            // Create the readable stream to upload the video
          , media: {
                body: Fs.createReadStream(VIDEO_PATH)
        }, function (err, data) {
            if (err) { return lien.end(err, 400); }

Before running the script, we have to install some dependencies:

$ npm i r-json lien opn bug-killer youtube-api

Then just run the script node your-script.js. You will have to allow your Google application to access your YouTube account and be patient until your video is uploaded. :tada:


If everything runs smoothly, you will see your video in your YouTube account. If you want to play with other YouTube resources check out this playground application.

If you have any questions, ideas or anything, check out the youtube-api package on GitHub and open an issue if the things are still unclear to you.

Happy uploading! :smile:

Read more »