Using GitLab API to add (POST) a yaml file to repository

I use Postman (or maybe other means) to add (POST) a yaml file to repository. The POST body is a JSON, where the “content” part should be the content of the yaml file. Obviously, many yaml characters are voilating JSON syntax.

Any idea how to get around that?

I noticed that when we GET a file, the content is Base64 encoded. So I attempted to POST Base64 encoded content, but it desn’t work until GitLab can decode it.

I guess I figured it out myself: JSON escape the yaml file then paste it to the “content” value part will make it work. Tried: JSON Escape and JSON Unescape Tool | CodersTool