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 listSep 3, 2024 19:15Yuriy LyfenkoYuriy LyfenkoScore: 3,464Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 3, 2024 19:153,29854,847,52020,007,00010,003,00093,048,832
2Sep 3, 2024 19:153,30554,004,82921,053,0009,022,00093,032,448
3Sep 3, 2024 19:153,31456,638,49721,111,0009,047,00093,151,232
4Sep 3, 2024 19:153,31956,286,16220,134,00010,067,00092,901,376
5Sep 3, 2024 19:153,33151,806,76520,211,00010,105,00093,102,080
6Sep 3, 2024 19:153,34252,908,95523,313,0007,095,00093,159,424
7Sep 3, 2024 19:153,46467,484,91521,352,00010,167,00093,138,944
8Sep 3, 2024 19:154,87271,203,63025,191,00019,145,00093,073,408
9Sep 3, 2024 19:156,88893,121,76728,308,00034,374,00093,286,400
10Sep 3, 2024 19:156,91884,644,26926,979,00035,973,00093,237,248
11Sep 3, 2024 19:157,01595,230,36030,922,00032,917,00093,233,152
12Sep 3, 2024 19:157,04885,136,41130,064,00034,073,00093,184,000