XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listOct 8, 2026 04:14Karthik ReddyKarthik ReddyScore: 35,048Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 8, 2026 04:2034,988329,393,429212,326,000106,072,00094,392,320
2Oct 8, 2026 04:2034,988328,861,002212,898,000105,496,00094,392,320
3Oct 8, 2026 04:2035,002329,613,014213,188,000105,335,00094,392,320
4Oct 8, 2026 04:2035,043329,452,330212,918,000105,974,00094,392,320
5Oct 8, 2026 04:2035,048330,882,684212,364,000106,580,00094,392,320
6Oct 8, 2026 04:2035,054330,037,996212,103,000106,897,00094,392,320
7Oct 8, 2026 04:2035,054329,984,864213,487,000105,506,00094,392,320
8Oct 8, 2026 04:2035,069329,682,641213,072,000106,060,00094,392,320
9Oct 8, 2026 04:2035,228331,508,331213,169,000107,408,00094,392,320