Skip to content

JSON.parse a Vector of {"key": key, "val": value} objects into a Dict #402

@Affie

Description

@Affie

Hi, I need help parsing a JSON payload of the form:

[
    { "key": "a", "val": "1" },
    { "key": "b", "val": "2" }
]

into a Dict{Symbol, String} using typed materialization.

I tried:

  • Wrapping the Dict in a struct (Metadata) and using StructUtils.make
    • I tried various simmilar things but can't quite make out how to interpret the errors like: ERROR: TypeError: in typeassert, expected Metadata, got a value of type Pair{Symbol, String}
  • metadata::Dict{Symbol, String} &(json=(lower=lowerMetadata, lift=liftMetadata))
    • Got this error: MethodError: Cannot convert an object of type JSON.Object{String, Any} to an object of type String

What is the correct way to use StructUtils.jl/JSON.jl in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions