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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user