purescript-httpurple/docs/Examples/JsonParsing/Main.js
2022-06-06 10:57:13 +01:00

17 lines
376 B
JavaScript

import * as Maybe from '../Data.Maybe/index.js'
export const parseJson = (str) => {
try {
return new Maybe.Just(JSON.parse(str))
} catch (error) {
return new Maybe.Nothing()
}
}
export const getName = (obj) => {
if (typeof obj.name == 'string') {
return new Maybe.Just(obj.name)
} else {
return new Maybe.Nothing()
}
}