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 22, 2023 14:08gchebanovgchebanovScore: 11,137Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 22, 2023 14:0810,468148,381,80995,259,771094,715,904
2Jul 22, 2023 14:0810,570158,391,17196,186,161094,711,808
3Jul 22, 2023 14:0810,763160,295,83097,939,630094,720,000
4Jul 22, 2023 14:0811,056127,962,94382,502,00018,110,00094,564,352
5Jul 22, 2023 14:0811,068127,250,45981,772,00018,947,00094,564,352
6Jul 22, 2023 14:0811,121129,766,95379,159,00022,044,00094,744,576
7Jul 22, 2023 14:0811,137123,494,71786,296,00015,051,00094,744,576
8Jul 22, 2023 14:0811,144124,171,77886,351,00015,061,00094,736,384
9Jul 22, 2023 14:0811,293129,791,18584,805,00017,958,00094,748,672
10Jul 22, 2023 14:0811,348125,796,29188,226,00015,038,00093,167,616
11Jul 22, 2023 14:0811,349128,937,94385,226,00018,047,00093,253,632
12Jul 22, 2023 14:0811,801132,214,22191,329,00016,058,00093,179,904