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 listJan 11, 2025 11:16Mikhail ShirokovMikhail ShirokovScore: 9,871Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jan 11, 2025 11:169,801110,296,77378,163,00011,023,000103,198,720
2Jan 11, 2025 11:169,858114,809,72177,749,00011,961,000103,059,456
3Jan 11, 2025 11:169,860112,273,60183,741,0005,981,000103,059,456
4Jan 11, 2025 11:169,865114,065,66980,799,0008,977,000103,219,200
5Jan 11, 2025 11:169,871115,989,95083,836,0005,988,000103,280,640
6Jan 11, 2025 11:169,872117,793,40478,853,00010,979,000103,182,336
7Jan 11, 2025 11:169,878112,735,34279,903,0009,987,000103,043,072
8Jan 11, 2025 11:169,884111,664,20579,950,0009,993,000103,313,408
9Jan 11, 2025 11:169,890108,959,96477,996,00011,999,000103,354,368