Skip to content

Commit 775a908

Browse files
authored
Merge pull request #4194 from RedisInsight/fe/bugfix/RI-6442---String-value-is-parsed-as-a-number-in-JSON
RI-6442 - String value is parsed as a number in JSON
2 parents 6e517b4 + 61cefbe commit 775a908

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ describe('JSONUtils', () => {
103103
expect(result).toBe(42)
104104
})
105105

106+
it('should preserve string values in JSON objects', () => {
107+
const input = '{"a":"111"}'
108+
const result = parseValue(input)
109+
expect(result.a).toBe('111')
110+
expect(typeof result.a).toBe('string')
111+
})
112+
113+
it('should handle mixed string and number values in JSON objects', () => {
114+
const input = '{"stringVal":"111","numberVal":111}'
115+
const result = parseValue(input)
116+
expect(result.stringVal).toBe('111')
117+
expect(typeof result.stringVal).toBe('string')
118+
expect(result.numberVal).toBe(111)
119+
expect(typeof result.numberVal).toBe('number')
120+
})
121+
106122
it('should handle string type with quotes', () => {
107123
expect(parseValue('"test"', 'string')).toBe('test')
108124
expect(parseValue('test', 'string')).toBe('test')

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ export const parseValue = (value: any, type?: string): any => {
122122
}
123123
const result: { [key: string]: any } = {}
124124
Object.entries(parsed).forEach(([key, val]) => {
125-
result[key] = parseValue(val)
125+
// This prevents double-parsing of JSON string values.
126+
if (typeof val === 'string') {
127+
result[key] = val
128+
} else {
129+
result[key] = parseValue(val)
130+
}
126131
})
127132
return result
128133
}

redisinsight/ui/src/slices/browser/rejson.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
22
import axios, { AxiosError, CancelTokenSource } from 'axios'
33

44
import { isNumber } from 'lodash'
5-
import { JSONbig } from 'json-bigint'
65
import { ApiEndpoints } from 'uiSrc/constants'
76
import { apiService } from 'uiSrc/services'
87
import { getBasedOnViewTypeEvent, sendEventTelemetry, TelemetryEvent, getJsonPathLevel } from 'uiSrc/telemetry'

0 commit comments

Comments
 (0)