Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ describe('JSONUtils', () => {
expect(result).toBe(42)
})

it('should preserve string values in JSON objects', () => {
const input = '{"a":"111"}'
const result = parseValue(input)
expect(result.a).toBe('111')
expect(typeof result.a).toBe('string')
})

it('should handle mixed string and number values in JSON objects', () => {
const input = '{"stringVal":"111","numberVal":111}'
const result = parseValue(input)
expect(result.stringVal).toBe('111')
expect(typeof result.stringVal).toBe('string')
expect(result.numberVal).toBe(111)
expect(typeof result.numberVal).toBe('number')
})

it('should handle string type with quotes', () => {
expect(parseValue('"test"', 'string')).toBe('test')
expect(parseValue('test', 'string')).toBe('test')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ export const parseValue = (value: any, type?: string): any => {
}
const result: { [key: string]: any } = {}
Object.entries(parsed).forEach(([key, val]) => {
result[key] = parseValue(val)
// This prevents double-parsing of JSON string values.
if (typeof val === 'string') {
result[key] = val
} else {
result[key] = parseValue(val)
}
})
return result
}
Expand Down
1 change: 0 additions & 1 deletion redisinsight/ui/src/slices/browser/rejson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import axios, { AxiosError, CancelTokenSource } from 'axios'

import { isNumber } from 'lodash'
import { JSONbig } from 'json-bigint'
import { ApiEndpoints } from 'uiSrc/constants'
import { apiService } from 'uiSrc/services'
import { getBasedOnViewTypeEvent, sendEventTelemetry, TelemetryEvent, getJsonPathLevel } from 'uiSrc/telemetry'
Expand Down
Loading