Troubleshooting JSON Parsing to HashMap

Hello, Is there a way I can parse json to a HashMap?
I always seem to get an error
    const toDecode = JSON.stringify(yaml.parse(dump, {}))

    const parsedLockfile = S.decodeUnknownSync(LOCK_SCHEMA)(JSON.parse(toDecode))


example JSON.parse(toDecode)
{
      test: {
        '/a.txt': 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb',
        '/a/b/file.a': 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
      }
    }

Schemas:
const LOCKFILE_MANAGER_SCHEMA = S.hashMapFromSelf({
  key: S.string.pipe(S.fromBrand(PathUtils.PosixPath)),
  value: S.string.pipe(S.fromBrand(MiniGit.Checksum)),
})

/**
 * Schema for the lock file.
 */

const LOCK_SCHEMA = S.mutable(S.record(S.string, LOCKFILE_MANAGER_SCHEMA))


error:
   { [x: string]: HashMap<<refinement schema>, <refinement schema>> }
    └─ ["test"]
       └─ Expected HashMap<<refinement schema>, <refinement schema>>, actual {"/a.txt":"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb","/a/b/file.a":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}


Should the schema be modified to have a transform to go from record to hashmap, since we can not represent hashmap in json?

Thank you for help!
Was this page helpful?