thoth-org / Thoth.Json

Library for working with JSON in a type safe manner, this libs is targeting Fable

Home Page:https://thoth-org.github.io/Thoth.Json/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decode.fromString should expose a path parameter

njlr opened this issue · comments

commented

This would be useful when you want to decode a substructure at various places.

It might look like this:

    let fromString' (path : string) (decoder : Decoder<'T>) =
        fun value ->
            try
               let json = JS.JSON.parse value
               fromValue path decoder json
            with
                | ex when Helpers.isSyntaxError ex ->
                    Error("Given an invalid JSON: " + ex.Message)

    let fromString (decoder : Decoder<'T>) =
        fromString' "$" decoder

Hum, it should be possible to add fromStringWithPath.

What is your scenario? The only case I can think of for this is if you have a JSON encoded in a JSON.

Decode.fromValue already accept a path if you already have access to a JSONValue (obj when using Fable "runtime").

I am closing because I don't have enough context for this issue.

If someone else needs it and can explains the use case, I will revisite adding support for fromStringWithPath