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:44Yuriy LyfenkoYuriy LyfenkoScore: 3,689Success
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:443,450650,060,12821,267,00010,127,00092,979,200
2Jul 26, 2024 21:443,461664,297,00823,097,0008,399,00092,979,200
3Jul 26, 2024 21:443,474655,449,77019,757,00011,854,00093,114,368
4Jul 26, 2024 21:443,483656,333,78323,774,0007,924,00092,917,760
5Jul 26, 2024 21:443,663688,003,83033,335,663094,658,560
6Jul 26, 2024 21:443,685699,107,92033,535,432094,613,504
7Jul 26, 2024 21:443,689699,657,90533,572,625094,613,504
8Jul 26, 2024 21:444,851662,607,92026,084,00018,058,00093,077,504
9Jul 26, 2024 21:445,375674,092,65122,960,00025,955,00093,151,232
10Jul 26, 2024 21:446,967683,985,33530,676,00032,721,00093,335,552
11Jul 26, 2024 21:447,254687,756,21038,591,00027,420,00093,052,928
12Jul 26, 2024 21:447,272687,759,30334,613,00031,559,00093,323,264