Small function to debug simple-json decoders

I’ve always found it annoying that simple-json doesn’t give you enough context for proper debugging. Case in point:

(NonEmptyList (NonEmpty
  (ErrorAtProperty "chummer"
    (ErrorAtProperty "skills"
      (ErrorAtProperty "skill"
        (ErrorAtIndex 2
          (ErrorAtProperty "skillgroup"
            (TypeMismatch "String" "Object"))))))

Is rather annoying to find the exact position in the JSON to take a closer look at the context. So I built a little function for it, maybe someone else finds it useful. Activate this spago override (until a new release is published):

let overrides = { json-pointer = upstream.json-pointer // { version="v1.1.0" } }

and install json-pointer. Use jqE / jqF depending on which context you’re in. The message will now look like this:

(NonEmpty "jq '.chummer.skills.skill[2].skillgroup' # to display the json at (TypeMismatch \"String\" \"Object\")"

So if you have the json at hand, you can use jq to display the specific json snippet. It’s been very useful to me so far, maybe someone of y’all might find it helpful.

If you already have the pointer stack, why not go ahead and interpret it to grab that value from whatever Foreign you are parsing? It doesn’t seem like you need to involve jq for that.

Yeah, when using it, I noticed I mostly grabbed one up, albeit it’s sometimes useful to have even more context, so jq is more generic. I may add a full read which provides the context as well.

Maybe you can return the object at each layer of the pointer stack, where the head of the list is the most specific element? This just seems really useful, but I can see lots of cases where it isn’t convenient to pipe things through to jq :smiley: