13
14
export function setProperty(text: string, originalPath: JSONPath, value: unknown, formattingOptions: FormattingOptions, getInsertionIndex?: (properties: string[]) => number): Edit[] {
16
>
const errors: ParseError[] = [];
17
>
const root = parseTree(text, errors);
18
>
let parent: Node | undefined = undefined;
19
>
20
>
let lastSegment: Segment | undefined = undefined;
21
>
while (path.length > 0) {
22
>
lastSegment = path.pop();
23
>
parent = findNodeAtLocation(root, path);
24
>
if (parent === undefined && value !== undefined) {
25
if (typeof lastSegment === 'string') {
26
value = { [lastSegment]: value };