Convert HTML to Atlassian Document Format (ADF) with PowerShell and ADFAPI
Working with Jira or Confluence often means dealing with Atlassian Document Format (ADF) — the structured JSON schema behind rich text content.
Manually writing ADF is tedious and error-prone. That’s where ADFAPI comes in: a hosted API that converts HTML or Markdown into clean, valid ADF.
In this post, we’ll show you how to use PowerShell to convert HTML to ADF JSON, both from a file and directly from a raw HTML string — and how to preview the results visually in your browser.
Why Use PowerShell?
PowerShell is common in enterprise environments. Whether you’re automating Jira issue creation, processing Confluence content, or prototyping, integrating HTML-to-ADF conversion into your scripts is easy.
Step 1: Prepare Your HTML
Example HTML to convert:
<h1>Hello Atlassian</h1>
<p>This content was <strong>converted</strong> to ADF with <a href="https://adfapi.dev">ADFAPI</a>.</p>
You can save this in a file called example.html
or use it directly as a raw string.
Step 2: Convert HTML to ADF with PowerShell
We will use this simple PowerShell script to call the ADFAPI HTML-to-ADF endpoint. Copy it into a ConvertHtmlToAdf.ps1
file.
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true)]
[string] $InputString,
[Parameter(Mandatory = $false)]
[string]$HtmlFileName,
[Parameter(Mandatory = $false)]
[string]$OutputFileName
)
# Define API endpoint
$apiUrl = "https://api.adfapi.dev/api/html"
# Read HTML content from file or stdin
if ($HtmlFileName) {
$htmlContent = Get-Content -Path $HtmlFileName -Raw
}
else {
$htmlContent = $InputString
}
# Send request with raw HTML and Content-Type: text/html
$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Body $htmlContent -ContentType "text/html"
# Output ADF JSON
$adfJson = $response | ConvertTo-Json -Depth 20
if ($OutputFileName) {
$adfJson | Out-File $OutputFileName
Write-Host "Conversion complete. ADF JSON saved to $OutputFileName"
}
else {
$adfJson
}
Run the file from a PowerShell terminal. Here are two options: reading HTML from a file or passing raw HTML directly:
Option 1: Read HTML from a File
Assuming you saved the example HTML in example.html
, run:
# Convert HTML from file and write to output file
.\ConvertHtmlToAdf.ps1 -HtmlFileName "example.html" -OutputFileName "output.adf.json"
# Convert HTML from file and print to console
.\ConvertHtmlToAdf.ps1 -HtmlFileName "example.html"
Option 2: Pass Raw HTML Directly
# Pass raw HTML string via pipeline and write to file
'<h1>Hello Atlassian</h1><p>This content was <strong>converted</strong> to ADF with <a href="https://adfapi.dev">ADFAPI</a>.</p>' | .\ConvertHtmlToAdf.ps1 -OutputFileName "output.adf.json"
# Pass raw HTML string via pipeline and print to console
'<h1>Hello Atlassian</h1><p>This content was <strong>converted</strong> to ADF with <a href="https://adfapi.dev">ADFAPI</a>.</p>' | .\ConvertHtmlToAdf.ps1
Step 3: Example Output
Here’s a snippet of what the ADF JSON looks like:
{
"version": 1,
"type": "doc",
"content": [
{
"type": "heading",
"attrs": {
"level": 1
},
"content": [
{
"type": "text",
"text": "Hello Atlassian"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "This content was "
},
{
"type": "text",
"text": "converted",
"marks": [
{
"type": "strong"
}
]
},
{
"type": "text",
"text": " to ADF with "
},
{
"type": "text",
"text": "ADFAPI",
"marks": [
{
"type": "link",
"attrs": {
"href": "https://adfapi.dev"
}
}
]
},
{
"type": "text",
"text": "."
}
]
}
]
}
With ADFAPI, PowerShell, and a simple preview setup, converting HTML to Atlassian Document Format and verifying it visually is effortless.
Try it out here or sign up to get a free API key.