I have a websocket which reads data that I parse into JSON files. I currently use JSON3.parse, and then convert each field into the form I want, which causes a lot of allocations and takes time.
The format of the JSON is a dictionary which is laid out like this:
Key1: A dictionary that I do not care about (and would ignore if I could)
Key2: A string which decides how I process the rest of the JSON
Key3: A Vector of size 1 which contains a dictionary which contains:
3a. Key3.1: A Vector of Vectors of length 4, containing numbers in string format (that I need to parse into numbers). I only need the first 2 numbers in each of these vectors of length 4. 3b. Key3.2: Same format as Key3.1 3c. Key3.3: Timestamp in nanos 3d. Key3.4: A number I don't need
I've looked at using JSON3 and OrderedStruct/StructTypes to efficiently do this, but I am having a hard time.
The original data is in UInt8 format, this is what I get after parsing.
{
"arg": {
"channel": "books50-l2-tbt",
"instId": "FIL-USD-210618"
},
"action": "snapshot",
"data": [
{
"asks": [
[
"69.604",
"100",
"0",
"1"
],
[
"69.624",
"27",
"0",
"1"
],
[
"69.63",
"946",
"0",
"2"
],
[
"69.728",
"302",
"0",
"1"
],
[
"69.729",
"1731",
"0",
"1"
],
[
"69.744",
"140",
"0",
"2"
],
[
"69.79",
"498",
"0",
"1"
],
[
"69.791",
"3015",
"0",
"1"
],
[
"69.841",
"50",
"0",
"1"
],
[
"70.006",
"5081",
"0",
"1"
],
[
"70.02",
"5129",
"0",
"1"
],
[
"70.199",
"29",
"0",
"1"
],
[
"70.224",
"3063",
"0",
"1"
],
[
"70.262",
"68",
"0",
"1"
],
[
"70.549",
"39",
"0",
"1"
],
[
"70.901",
"22",
"0",
"1"
],
[
"71.06",
"2047",
"0",
"1"
],
[
"71.255",
"43",
"0",
"1"
],
[
"71.399",
"37",
"0",
"1"
],
[
"71.498",
"1972",
"0",
"1"
],
[
"71.611",
"21",
"0",
"1"
],
[
"71.711",
"2033",
"0",
"1"
],
[
"71.755",
"49",
"0",
"1"
],
[
"71.969",
"32",
"0",
"1"
],
[
"72.113",
"32",
"0",
"1"
],
[
"72.328",
"43",
"0",
"1"
],
[
"72.473",
"22",
"0",
"1"
],
[
"72.689",
"25",
"0",
"1"
],
[
"72.835",
"50",
"0",
"1"
],
[
"73.052",
"34",
"0",
"1"
],
[
"73.199",
"31",
"0",
"1"
],
[
"73.224",
"2",
"0",
"1"
],
[
"73.564",
"24",
"0",
"1"
],
[
"73.931",
"44",
"0",
"1"
],
[
"74.3",
"36",
"0",
"1"
],
[
"76.885",
"2",
"0",
"1"
],
[
"80.729",
"2",
"0",
"1"
],
[
"84.765",
"3",
"0",
"1"
],
[
"89.003",
"2",
"0",
"1"
],
[
"93.453",
"1",
"0",
"1"
],
[
"98.125",
"2",
"0",
"1"
],
[
"103.031",
"2",
"0",
"1"
],
[
"108.182",
"2",
"0",
"1"
],
[
"113.591",
"1",
"0",
"1"
]
],
"bids": [
[
"69.47",
"63",
"0",
"1"
],
[
"69.469",
"100",
"0",
"1"
],
[
"69.419",
"50",
"0",
"1"
],
[
"69.336",
"70",
"0",
"1"
],
[
"69.335",
"70",
"0",
"1"
],
[
"69.273",
"302",
"0",
"1"
],
[
"69.272",
"1290",
"0",
"1"
],
[
"69.254",
"498",
"0",
"1"
],
[
"69.253",
"3015",
"0",
"1"
],
[
"69.219",
"50",
"0",
"1"
],
[
"69.217",
"120",
"0",
"2"
],
[
"69.207",
"70",
"0",
"1"
],
[
"69.179",
"67",
"0",
"1"
],
[
"69.136",
"70",
"0",
"1"
],
[
"69.134",
"160",
"0",
"2"
],
[
"69.034",
"4685",
"0",
"2"
],
[
"68.942",
"55",
"0",
"1"
],
[
"68.744",
"5101",
"0",
"1"
],
[
"68.742",
"74",
"0",
"2"
],
[
"68.619",
"3008",
"0",
"1"
],
[
"68.399",
"104",
"0",
"2"
],
[
"68.058",
"81",
"0",
"2"
],
[
"67.915",
"1973",
"0",
"1"
],
[
"67.718",
"109",
"0",
"2"
],
[
"67.593",
"2034",
"0",
"1"
],
[
"67.38",
"103",
"0",
"2"
],
[
"67.184",
"2038",
"0",
"1"
],
[
"67.044",
"57",
"0",
"2"
],
[
"66.709",
"71",
"0",
"2"
],
[
"66.376",
"101",
"0",
"2"
],
[
"66.252",
"2",
"0",
"1"
],
[
"66.045",
"59",
"0",
"2"
],
[
"62.94",
"1",
"0",
"1"
],
[
"59.793",
"3",
"0",
"1"
],
[
"56.804",
"3",
"0",
"1"
],
[
"53.964",
"2",
"0",
"1"
],
[
"51.266",
"2",
"0",
"1"
],
[
"48.703",
"2",
"0",
"1"
],
[
"46.268",
"2",
"0",
"1"
],
[
"43.955",
"2",
"0",
"1"
],
[
"41.758",
"1",
"0",
"1"
]
],
"ts": "1623570748052",
"checksum": 599613499
}
]
}