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 26, 2024 21:52Yuriy LyfenkoYuriy LyfenkoScore: 3,675Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 21:523,516652,116,81822,000,00010,000,00093,097,984
2Jul 26, 2024 21:523,521651,853,04321,028,00011,014,00093,134,848
3Jul 26, 2024 21:523,525654,471,01023,059,0009,023,00093,020,160
4Jul 26, 2024 21:523,527655,322,50824,069,0008,023,00093,155,328
5Jul 26, 2024 21:523,533650,266,86724,110,0008,036,00092,897,280
6Jul 26, 2024 21:523,546655,117,28224,202,0008,067,00092,905,472
7Jul 26, 2024 21:523,675660,657,61022,991,00010,450,00092,971,008
8Jul 26, 2024 21:523,724694,876,36533,890,298094,642,176
9Jul 26, 2024 21:523,728698,500,35333,924,160094,613,504
10Jul 26, 2024 21:523,740703,841,04334,037,010094,609,408
11Jul 26, 2024 21:525,079673,221,40124,116,00022,106,00093,171,712
12Jul 26, 2024 21:525,571675,630,53426,839,00023,857,00093,143,040