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 listApr 21, 2024 23:33Joad NacerJoad NacerScore: 3,859Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:333,83862,562,17923,948,00010,976,00092,917,760
2Apr 21, 2024 23:333,83864,113,09023,949,00010,976,00092,901,376
3Apr 21, 2024 23:333,84062,605,52824,963,0009,985,00092,925,952
4Apr 21, 2024 23:333,84159,914,67424,965,0009,986,00092,909,568
5Apr 21, 2024 23:333,84761,768,13527,006,0008,001,00092,889,088
6Apr 21, 2024 23:333,85258,992,52724,035,00011,016,00092,930,048
7Apr 21, 2024 23:333,85965,418,13625,086,00010,034,00092,897,280
8Apr 21, 2024 23:333,89961,354,89526,356,0009,123,00092,954,624
9Apr 21, 2024 23:334,171108,508,37837,952,402094,494,720
10Apr 21, 2024 23:334,174104,191,22237,985,728094,494,720
11Apr 21, 2024 23:334,186112,146,02538,092,974094,482,432
12Apr 21, 2024 23:335,91784,141,00029,916,00023,933,00093,081,600