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 listJul 22, 2023 14:16gchebanovgchebanovScore: 10,931Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 22, 2023 14:1610,452155,635,55295,109,410094,715,904
2Jul 22, 2023 14:1610,495153,359,82395,500,964094,715,904
3Jul 22, 2023 14:1610,706159,609,34297,428,825094,703,616
4Jul 22, 2023 14:1610,867124,196,15977,917,00020,977,00094,740,480
5Jul 22, 2023 14:1610,897124,425,53379,131,00020,033,00094,744,576
6Jul 22, 2023 14:1610,899120,403,10179,143,00020,036,00094,564,352
7Jul 22, 2023 14:1610,931128,625,81481,387,00018,086,00094,564,352
8Jul 22, 2023 14:1610,964130,877,14083,810,00015,963,00094,740,480
9Jul 22, 2023 14:1610,992124,956,53979,019,00021,005,00094,752,768
10Jul 22, 2023 14:1611,110123,254,15276,076,00025,025,00093,024,256
11Jul 22, 2023 14:1611,164128,611,94778,459,00023,135,00093,171,712
12Jul 22, 2023 14:1611,344127,692,02684,189,00019,042,00093,175,808