wtf_wikipedia

parse MediaWiki markup into structured JSON

wikitext
{
  "title": "Toronto",
  "categories": [],
  "sections": [
    {
      "title": "",
      "depth": 0,
      "paragraphs": [
        {
          "sentences": [
            {
              "text": "Toronto is the capital city of the Canadian province of Ontario.",
              "links": [
                {
                  "type": "internal",
                  "page": "Canadian"
                },
                {
                  "type": "internal",
                  "page": "Ontario"
                }
              ],
              "formatting": {
                "bold": [
                  "Toronto"
                ]
              }
            },
            {
              "text": "It is the most populous city in Canada, with a population of 2,794,356 people."
            }
          ]
        }
      ]
    },
    {
      "title": "History",
      "depth": 0,
      "paragraphs": [
        {
          "sentences": [
            {
              "text": "The city was originally named York and was founded in 1793.",
              "links": [
                {
                  "text": "1793",
                  "type": "internal",
                  "page": "1793"
                }
              ],
              "formatting": {
                "bold": [
                  "York"
                ]
              }
            },
            {
              "text": "It was renamed Toronto in 1834.",
              "links": [
                {
                  "text": "1834",
                  "type": "internal",
                  "page": "1834"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "title": "Geography",
      "depth": 0,
      "paragraphs": [
        {
          "sentences": [
            {
              "text": "Toronto is on the northwestern shore of Lake Ontario.",
              "links": [
                {
                  "type": "internal",
                  "page": "Lake Ontario"
                }
              ]
            }
          ]
        }
      ],
      "tables": [
        [
          {
            "Year": {
              "text": "1851",
              "number": 1851
            },
            "Population": {
              "text": "30,775",
              "number": 30775
            }
          },
          {
            "Year": {
              "text": "1901",
              "number": 1901
            },
            "Population": {
              "text": "208,040",
              "number": 208040
            }
          },
          {
            "Year": {
              "text": "2021",
              "number": 2021
            },
            "Population": {
              "text": "2,794,356",
              "number": 2794356
            }
          }
        ]
      ]
    },
    {
      "title": "References",
      "depth": 0,
      "templates": [
        {
          "template": "reflist"
        }
      ]
    }
  ]
}
wtf(input).json()