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 listDec 31, 2024 06:36Mikhail ShirokovMikhail ShirokovScore: 26,988Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 31, 2024 06:3626,900274,168,469199,828,00044,961,000105,222,144
2Dec 31, 2024 06:3626,912271,095,942188,919,00055,976,000105,115,648
3Dec 31, 2024 06:3626,938271,687,624190,106,00055,030,000105,242,624
4Dec 31, 2024 06:3626,987273,164,345186,682,00058,899,000105,226,240
5Dec 31, 2024 06:3626,988274,386,087197,672,00047,920,000105,127,936
6Dec 31, 2024 06:3627,003283,362,107195,783,00049,944,000105,091,072
7Dec 31, 2024 06:3627,037277,720,236192,029,00054,008,000105,201,664
8Dec 31, 2024 06:3627,063276,105,950185,203,00061,067,000105,152,512
9Dec 31, 2024 06:3627,098275,150,634190,685,00055,907,000105,127,936