mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 23:25:43 +01:00
Answer stability round 1: read JSON with the library's own reader, since V8's JSON.parse misreads an escaped key
This commit is contained in:
@@ -9,6 +9,7 @@ import { infoStringCarries } from './commonmark/grammar.ts'
|
||||
import { isAdfNode } from '../adf/document.ts'
|
||||
import { isJsonValue, nestingDepth, overNested } from '../json-value.ts'
|
||||
import { largestNesting } from '../nesting.ts'
|
||||
import { parseJsonText } from '../json-text.ts'
|
||||
import { serializeCanonicalJson } from '../canonical-json.ts'
|
||||
|
||||
export const carryFencePrefix = 'adf:'
|
||||
@@ -91,12 +92,3 @@ function typedValue(value: JsonValue, type: string): Read<JsonValue> {
|
||||
if ('type' in value) return { fault: unsupportedNodeShape(`the ${carryFencePrefix}${type} fence names its node's type: this JSON holds a type as well; ${fenceEscape(type)}`) }
|
||||
return { value: { ...value, type } }
|
||||
}
|
||||
|
||||
function parseJsonText(raw: string): { value: unknown } | undefined {
|
||||
try {
|
||||
const value: unknown = JSON.parse(raw)
|
||||
return { value }
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user