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 21:56Yuriy LyfenkoYuriy LyfenkoScore: 3,616Success
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 21:563,368655,621,08328,674,0001,977,00093,159,424
2Jul 26, 2024 21:563,370656,264,25225,559,0005,111,00092,925,952
3Jul 26, 2024 21:563,384657,451,38025,830,0004,967,00093,147,136
4Jul 26, 2024 21:563,388657,031,61228,839,0001,988,00093,130,752
5Jul 26, 2024 21:563,388657,648,69613,925,00016,909,00092,880,896
6Jul 26, 2024 21:563,537655,984,51528,163,0004,023,00092,971,008
7Jul 26, 2024 21:563,616694,719,53532,906,298094,609,408
8Jul 26, 2024 21:563,619705,688,83032,930,471094,613,504
9Jul 26, 2024 21:563,625691,370,27032,988,235094,642,176
10Jul 26, 2024 21:565,758685,486,58632,245,00020,153,00093,126,656
11Jul 26, 2024 21:566,628694,324,70836,800,00023,511,00093,343,744
12Jul 26, 2024 21:567,162688,797,05930,080,00035,093,00093,323,264