demystifyfp / FsConfig

FsConfig is a F# library for reading configuration data from environment variables and AppSettings with type safety.

Home Page:https://www.demystifyfp.com/FsConfig/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FsConfig doesn't support JSON Array

AntyaDev opened this issue · comments

Description

FsConfig doesn't support JSON Array

Repro steps

  1. Define config.json
    here is a JSON:
    {
    data: ["1", "2"]
    }

  2. Define F# type
    type Config = {
    Data: string list
    }

  3. Parse
    let config = ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("config.json")
    .Build()
    |> AppConfig

let result = config.Get()

Expected behavior

result should contain not empty Config.Data

Actual behavior

result contains empty Config.Data

  • Operating system Windows 10 x64

Hi @AntyaDev,

Can you try with comma separated string instead of the SON array like below?

{
  "data": "1,2"
}

The documention for the list is here https://github.com/demystifyfp/FsConfig#list-type

It will not work with complex types.
I mean,
settings: MySettings list

type MySettings = {
}

It is a current limitation. It is due to the fact the list was initially supported for environment variables where we don't have the sophistication of representing a list of a complex type as a string. I am open to a PR or design suggestion if you'd like to contribute.

Ah, I see now

FsConfig is a F# library for reading configuration data from environment variables
It's related only for env variables... I just thought FsConfig means - I can parse any config because the name is very general.

@AntyaDev Just to clarify, It supports AppConfig in addition to Env variables with this limitation.