* OAS 2 request and response examples for json cases * OAS 3 request and response examples for json cases * OAS2 and OAS3 tests * jsonParse utils for syntax highlighting
16 lines
415 B
JavaScript
16 lines
415 B
JavaScript
export function canJsonParse(str) {
|
|
try {
|
|
let testValueForJson = JSON.parse(str)
|
|
return testValueForJson ? true : false
|
|
} catch (e) {
|
|
// exception: string is not valid json
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function getKnownSyntaxHighlighterLanguage(val) {
|
|
// to start, only check for json. can expand as needed in future
|
|
const isValidJson = canJsonParse(val)
|
|
return isValidJson ? "json" : null
|
|
}
|