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 listJun 23, 2024 17:54AnSaAnSaError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 17:4900000Error: invalid character '"' after object key:value pair
2Jun 23, 2024 17:543,87861,386,33227,226,0008,067,00091,955,200
3Jun 23, 2024 17:543,87959,147,71927,229,0008,067,00091,906,048
4Jun 23, 2024 17:543,88254,992,37825,235,00010,094,00091,893,760
5Jun 23, 2024 17:393,97962,394,45524,140,00012,070,00091,881,472
6Jun 23, 2024 17:393,98861,209,17923,186,00013,105,00092,119,040
7Jun 23, 2024 17:394,02163,474,82724,394,00012,197,00092,037,120
8Jun 23, 2024 17:394,06066,814,11823,963,00012,980,00092,147,712
9Jun 23, 2024 17:394,42862,562,16524,179,00016,119,00092,225,536
10Jun 23, 2024 17:394,47072,946,90823,812,00016,867,00092,160,000
11Jun 23, 2024 17:544,52364,924,10922,087,00019,075,00092,004,352
12Jun 23, 2024 17:545,56381,473,91117,866,00032,756,00092,119,040
13Jun 23, 2024 17:545,75479,927,60824,167,00028,195,00092,119,040
14Jun 23, 2024 17:546,830113,309,34662,154,957092,798,976
15Jun 23, 2024 17:546,852119,913,49462,349,150092,528,640
16Jun 23, 2024 17:546,853115,544,76262,365,549092,520,448
17Jun 23, 2024 17:396,926139,981,64963,024,088092,528,640
18Jun 23, 2024 17:396,949129,493,98463,232,028092,520,448
19Jun 23, 2024 17:396,967128,168,23563,398,170092,520,448
20Jun 23, 2024 17:397,46096,070,91327,954,00039,935,00092,299,264
21Jun 23, 2024 17:548,564108,125,51328,976,00048,960,00092,467,200
22Jun 23, 2024 17:398,725110,537,96225,127,00054,275,00092,266,496
23Jun 23, 2024 17:398,813104,996,72031,076,00049,120,00092,413,952
24Jun 23, 2024 17:548,845108,441,17032,194,00048,291,00092,409,856
25Jun 23, 2024 17:548,884105,258,42823,953,00056,889,00092,483,584