processing: support duplicated keys when parsing json logs (#116116)

* processing: support duplicated keys when parsing json logs

* Add regression test

* prettier
This commit is contained in:
Matias Chomicki
2026-01-12 13:37:17 +01:00
committed by GitHub
parent 0d7f46c08a
commit 2aedbdb76f
2 changed files with 19 additions and 1 deletions
@@ -190,6 +190,22 @@ describe('preProcessLogs', () => {
expect(logListModel.body).not.toBe(entry);
});
test('Prettifies JSON with duplicate keys', () => {
const entry = '{"key": "value", "key": "otherValue"}';
const logListModel = createLogLine(
{ entry },
{
escape: false,
order: LogsSortOrder.Descending,
timeZone: 'browser',
wrapLogMessage: true, // wrapped
prettifyJSON: true,
}
);
expect(logListModel.entry).toBe(entry);
expect(logListModel.body).not.toBe(entry);
});
test('Prettifies and escapes wrapped JSON', () => {
const entry = '{"key": "value", "otherKey": "other\\nValue"}';
const logListModel = createLogLine(
@@ -135,7 +135,9 @@ export class LogListModel implements LogRowModel {
get body(): string {
if (this._body === undefined) {
try {
const parsed = parse(this.raw);
const parsed = parse(this.raw, undefined, {
onDuplicateKey: ({ newValue }) => newValue,
});
if (typeof parsed === 'object' && parsed !== null && !(parsed instanceof LosslessNumber)) {
this._json = true;
}