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 listMay 9, 2024 23:47Joad NacerJoad NacerError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:4500000Error: EOF
2May 9, 2024 23:483,51559,191,23420,989,00010,994,00093,126,656
3May 9, 2024 23:473,56755,371,62823,329,0009,128,00092,905,472
4May 9, 2024 23:473,59157,566,59120,795,00011,883,00092,962,816
5May 9, 2024 23:483,59364,191,63521,798,00010,899,00092,901,376
6May 9, 2024 23:473,59557,653,66821,812,00010,906,00092,930,048
7May 9, 2024 23:483,59663,933,23720,827,00011,901,00092,938,240
8May 9, 2024 23:483,60458,962,29520,873,00011,927,00092,913,664
9May 9, 2024 23:473,60659,695,40720,885,00011,934,00092,917,760
10May 9, 2024 23:483,60759,062,47320,887,00011,935,00092,905,472
11May 9, 2024 23:473,62063,308,05320,966,00011,980,00092,901,376
12May 9, 2024 23:483,63161,849,04521,029,00012,016,00092,909,568
13May 9, 2024 23:473,78192,475,34934,402,982094,748,672
14May 9, 2024 23:483,79591,916,61734,531,695094,490,624
15May 9, 2024 23:473,810100,766,40334,672,820094,486,528
16May 9, 2024 23:483,81184,702,21934,676,133094,498,816
17May 9, 2024 23:483,821105,258,92334,771,286094,486,528
18May 9, 2024 23:473,825113,405,74534,803,923094,486,528
19May 9, 2024 23:474,84870,091,91023,061,00021,056,00093,093,888
20May 9, 2024 23:487,01487,519,24726,928,00036,902,00093,179,904
21May 9, 2024 23:487,39794,576,90225,117,00042,196,00093,376,512
22May 9, 2024 23:477,51893,914,83026,159,00042,257,00093,233,152
23May 9, 2024 23:477,56893,159,51724,954,00043,919,00093,257,728
24May 9, 2024 23:477,63593,521,38026,180,00043,299,00093,212,672
25May 9, 2024 23:487,666105,444,81926,908,00042,854,00093,216,768