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:01Yuriy LyfenkoYuriy LyfenkoScore: 3,618Success
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:013,410659,064,18524,022,0007,006,00093,167,616
2Jul 26, 2024 22:013,415656,987,67221,049,00010,023,00093,167,616
3Jul 26, 2024 22:013,424653,490,76922,112,0009,046,00093,233,152
4Jul 26, 2024 22:013,425650,358,12723,898,0007,273,00092,917,760
5Jul 26, 2024 22:013,432657,431,63621,156,00010,074,00092,946,432
6Jul 26, 2024 22:013,594659,570,48723,783,0008,918,00092,971,008
7Jul 26, 2024 22:013,618694,256,89232,922,318094,650,368
8Jul 26, 2024 22:013,620683,930,30732,942,396094,613,504
9Jul 26, 2024 22:013,635692,282,07733,076,330094,613,504
10Jul 26, 2024 22:013,738657,883,74220,012,00014,008,00093,220,864
11Jul 26, 2024 22:016,039674,959,72529,515,00025,444,00093,114,368
12Jul 26, 2024 22:017,170689,954,49231,119,00034,131,00093,323,264