#Help with type encoding for JSON file

4 messages · Page 1 of 1 (latest)

eager swallow
#

Hi , I',m trying to parse a json file with serde_json and I'm currently typing a field as a so

scope:Vec<String>

but the issue is that the file I'm parsing could be in any of these two forms

{
  scope:"some_scope"
}
// or
{
  scope:["multiple","possible","scopes"]
}

Is there any way I can handle this ?

night thorn
#

have scope be an enum that contains either a String or a Vec<String>

#

then you could use a From conversion to make it just a single Vec

eager swallow
#

How would that look please ?