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 26, 2024 22:23Yuriy LyfenkoYuriy LyfenkoScore: 3,459Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 22:233,327650,082,44322,202,0008,073,00093,204,480
2Jul 26, 2024 22:233,334652,469,46624,271,0006,067,00092,852,224
3Jul 26, 2024 22:233,337651,109,51324,292,0006,073,00093,126,656
4Jul 26, 2024 22:233,338653,011,93224,302,0006,075,00092,884,992
5Jul 26, 2024 22:233,341652,383,87223,311,0007,094,00092,864,512
6Jul 26, 2024 22:233,458686,002,67231,467,793094,654,464
7Jul 26, 2024 22:233,459698,937,24531,475,199094,609,408
8Jul 26, 2024 22:233,471685,081,48231,586,606094,773,248
9Jul 26, 2024 22:234,042662,056,56523,861,00012,925,00093,204,480
10Jul 26, 2024 22:235,560676,766,47824,801,00025,793,00093,130,752
11Jul 26, 2024 22:236,833689,733,19730,579,00031,598,00093,335,552
12Jul 26, 2024 22:237,066692,613,05338,179,00026,122,00093,323,264