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 22, 2024 14:32Yuriy LyfenkoYuriy LyfenkoScore: 3,632Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 14:323,484558,017,83822,498,0009,203,00092,872,704
2Apr 22, 2024 14:323,488562,654,02720,832,00010,912,00092,901,376
3Apr 22, 2024 14:323,489560,688,40120,836,00010,914,00092,921,856
4Apr 22, 2024 14:323,494557,939,29721,859,0009,936,00092,934,144
5Apr 22, 2024 14:323,499555,802,55921,889,0009,949,00092,925,952
6Apr 22, 2024 14:323,504560,999,20921,924,0009,965,00092,913,664
7Apr 22, 2024 14:323,632590,207,77233,047,059094,605,312
8Apr 22, 2024 14:323,638604,541,44033,102,229094,609,408
9Apr 22, 2024 14:323,655601,983,54133,258,986094,609,408
10Apr 22, 2024 14:325,902576,050,71624,865,00028,843,00093,118,464
11Apr 22, 2024 14:326,539586,568,10624,204,00035,298,00093,089,792
12Apr 22, 2024 14:326,915590,034,13231,963,00030,964,00093,077,504