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 29, 2023 10:16Yurkov AlekseyYurkov AlekseyScore: 12,794Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 29, 2023 10:167,037117,940,22764,039,191092,573,696
2Jul 29, 2023 10:167,047144,644,24164,126,371092,573,696
3Jul 29, 2023 10:167,061124,319,76564,253,782092,569,600
4Jul 29, 2023 10:1612,784139,071,253100,285,00016,045,00092,672,000
5Jul 29, 2023 10:1612,787149,056,418100,316,00016,050,00092,471,296
6Jul 29, 2023 10:1612,793143,583,099100,361,00016,057,00092,663,808
7Jul 29, 2023 10:1612,794144,581,648100,366,00016,058,00092,471,296
8Jul 29, 2023 10:1612,824139,580,49896,752,00019,948,00092,704,768
9Jul 29, 2023 10:1612,827141,091,30699,767,00016,960,00092,704,768
10Jul 29, 2023 10:1613,027145,389,58098,626,00019,924,00092,073,984
11Jul 29, 2023 10:1613,082146,789,864101,040,00018,007,00092,209,152
12Jul 29, 2023 10:1613,114148,362,560101,290,00018,051,00092,184,576