| | 1 | |
|
| | 2 | | """ |
| | 3 | | _column_to_pointer{T}(p::Pointer) |
| | 4 | |
|
| | 5 | | construct JSONPointer.Pointer with specified type |
| | 6 | | """ |
| 232 | 7 | | function _column_to_pointer(token_string::AbstractString)::Pointer |
| 232 | 8 | | if !startswith(token_string, JSONPointer.TOKEN_PREFIX) |
| 16 | 9 | | token_string = "/" * token_string |
| | 10 | | end |
| 232 | 11 | | if endswith(token_string, "}") |
| 24 | 12 | | x = split(token_string, "{") |
| 24 | 13 | | p = Pointer(x[1]) |
| 24 | 14 | | T = jsontype_to_juliatype(x[2][1:end-1]) |
| | 15 | |
|
| 24 | 16 | | return Pointer{Array{T, 1}}(p.tokens) |
| | 17 | | else |
| 208 | 18 | | return Pointer(token_string) |
| | 19 | | end |
| | 20 | | end |
| 0 | 21 | | _column_to_pointer(token) = _column_to_pointer(string(token)) |
| | 22 | |
|
| 24 | 23 | | function jsontype_to_juliatype(t) |
| 34 | 24 | | if t == "string" |
| 5 | 25 | | return String |
| 29 | 26 | | elseif t == "number" |
| 9 | 27 | | return Float64 |
| | 28 | | # JSON does not have distinct types for integers and floating-point values |
| | 29 | | # but Excel does, and distinguishing integer is useful for many things. |
| 10 | 30 | | elseif t == "integer" |
| 10 | 31 | | return Int |
| 0 | 32 | | elseif t == "object" |
| 0 | 33 | | return OrderedDict{String,Any} |
| 0 | 34 | | elseif t == "array" |
| 0 | 35 | | return Vector{Any} |
| 0 | 36 | | elseif t == "boolean" |
| 0 | 37 | | return Bool |
| 0 | 38 | | elseif t == "null" |
| 0 | 39 | | return Missing |
| | 40 | | else |
| 0 | 41 | | error( |
| | 42 | | "You specified a type that JSON doesn't recognize! Instead of " * |
| | 43 | | "`::$t`, you must use one of `::string`, `::number`, " * |
| | 44 | | "`::object`, `::array`, `::boolean`, or `::null`." |
| | 45 | | ) |
| | 46 | | end |
| | 47 | | end |
| | 48 | |
|
| 32 | 49 | | function pointer_to_colname(p::Pointer{T})::String where T |
| 32 | 50 | | col = "/" * join(p.tokens, "/") |
| 32 | 51 | | t = juliatype_to_jsontype(T) |
| 32 | 52 | | if t == "array" |
| 4 | 53 | | col *= "::$t" |
| 4 | 54 | | t2 = juliatype_to_jsontype(eltype(T)) |
| 4 | 55 | | if !isempty(t2) |
| 3 | 56 | | col *= "{$t2}" |
| | 57 | | end |
| 28 | 58 | | elseif !isempty(t) |
| 0 | 59 | | col *= "::$t" |
| | 60 | | end |
| 32 | 61 | | return col |
| | 62 | | end |
| | 63 | |
|
| 36 | 64 | | function juliatype_to_jsontype(T) |
| 36 | 65 | | if T <: OrderedDict |
| 0 | 66 | | t = "object" |
| 36 | 67 | | elseif T <: Array |
| 4 | 68 | | t = "array" |
| 32 | 69 | | elseif T == String |
| 1 | 70 | | t = "string" |
| 31 | 71 | | elseif T == Float64 |
| 1 | 72 | | t = "number" |
| 30 | 73 | | elseif T == Int |
| 1 | 74 | | t = "integer" |
| 29 | 75 | | elseif T == Bool |
| 0 | 76 | | t = "boolean" |
| 29 | 77 | | elseif T == Missing |
| 0 | 78 | | t = "null" |
| 29 | 79 | | elseif T == Nothing |
| 0 | 80 | | t = "null" |
| 29 | 81 | | elseif T == Any |
| 29 | 82 | | t = "" |
| | 83 | | else |
| 0 | 84 | | @warn("cannot find jsontype from $T, returning empty string") |
| 0 | 85 | | t = "" |
| | 86 | | end |
| 36 | 87 | | return t |
| | 88 | | end |