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 27, 2024 14:37Joad NacerJoad NacerScore: 3,474Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:373,26753,542,83818,830,00010,902,00093,102,080
2Jul 27, 2024 14:373,34756,639,32521,319,0009,137,00092,954,624
3Jul 27, 2024 14:373,34857,118,21621,325,0009,139,00093,192,192
4Jul 27, 2024 14:373,34954,657,16520,317,00010,158,00093,032,448
5Jul 27, 2024 14:373,35655,114,37520,361,00010,180,00093,155,328
6Jul 27, 2024 14:373,38555,430,55020,867,0009,936,00093,122,560
7Jul 27, 2024 14:373,47492,789,85731,612,155094,760,960
8Jul 27, 2024 14:373,48893,676,53231,742,499094,502,912
9Jul 27, 2024 14:373,49890,870,50231,829,175094,629,888
10Jul 27, 2024 14:374,10963,736,03920,214,00017,182,00093,040,640
11Jul 27, 2024 14:377,20191,950,85024,195,00041,334,00093,212,672
12Jul 27, 2024 14:377,339104,773,42323,924,00042,863,00093,319,168