Hola all. I'm trying to build a JsonObject from kn...
# getting-started
m
Hola all. I'm trying to build a JsonObject from known data, by the following. And guesses why it's not working?
Copy code
val samplemessage = json {
    "decodes" to {
        "ref" to 43989
        "vrm" to "AV11LPR"
        "frameID" to 12029991
        "spacedVRM" to "AV11 LPR"
        "seenCount" to 18
        "cameraName" to "Test_MAV_IQ"
        "decodeID" to 44606
        "repeatedPlate" to false
        "timeStamp" to
                {"Time" to 1473670749
                    "ms" to 64
                    "LocalTime" to 1473677949}
        "timeSync" to
                {"timeMode" to 0
                    "lastSyncTime" to 1473062065
                    "lastSyncSource" to "SNTP"
                    "lastSyncInfo" to "192.53.103.108"}
        "direction" to 126
        "motion" to "towards"
        "frameTimeRef" to 606284767
    }
}
s
what does “not working” mean
That could refer to a compile-time error, a runtime error, a jsonobject that doesn’t yield what you think it should yield, etc, etc
also that segment
Copy code
"timeStamp" to
                {"Time" to 1473670749
                    "ms" to 64
                    "LocalTime" to 1473677949}
doesn’t look like what you want, unless your
json
builder can take a
Pair<String, () -> Pair<String, Int>>
and automagically turn it into a json object
Also, what json library is this? #klaxon, maybe?
m
No errors at all, but no content in the JsonObject. (At least, as far as I can tell in the debugger)
s
do you at least have a
decodes
field?
Or maybe the builder discards pairs it can’t cleanly make a json mapping for
decodes
at the top level is being mapped to a lambda, not another json object
m
kotlinx.serialization.json, for the library.
Aha! You were right on the last bit. "decodes" to json {} fixed it. Onwards to new and interesting errors.
Thanks.