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 27, 2024 19:57Joad NacerJoad NacerScore: 3,392Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 19:573,18558,579,71418,990,0009,995,00093,192,192
2Jul 27, 2024 19:573,23451,411,85820,298,0009,134,00093,057,024
3Jul 27, 2024 19:573,25362,346,83820,417,0009,187,00093,057,024
4Jul 27, 2024 19:573,27358,602,26419,859,0009,929,00093,077,504
5Jul 27, 2024 19:573,27558,306,62418,872,00010,926,00093,093,888
6Jul 27, 2024 19:573,38089,731,49830,753,916094,494,720
7Jul 27, 2024 19:573,39283,662,43130,870,081094,498,816
8Jul 27, 2024 19:573,40392,446,83130,964,890094,498,816
9Jul 27, 2024 19:573,88869,961,46722,240,00013,142,00093,151,232
10Jul 27, 2024 19:576,08879,092,20721,153,00034,249,00093,294,592
11Jul 27, 2024 19:577,03295,413,84722,996,00040,993,00093,237,248
12Jul 27, 2024 19:577,14395,454,94823,002,00042,003,00093,261,824