Repository: DiceDB/dice
File: tests/json_test.go (Go)

Code before:
		ja.Assertf(result.(string), `true`)
	})

	t.Run("Set and Get Boolean False", func(t *testing.T) {
		setCmd := `JSON.SET booleanFalse $ false`
		result := fireCommand(conn, setCmd)
		assert.Equal(t, "OK", result)

		getCmd := `JSON.GET booleanFalse`
		result = fireCommand(conn, getCmd)
		ja.Assertf(result.(string), `false`)
	})

	t.Run("Set and Get Simple JSON", func(t *testing.T) {
		setCmd := `JSON.SET user $ {"name":"John","age":30}`
		result := fireCommand(conn, setCmd)
		assert.Equal(t, "OK", result)

		getCmd := `JSON.GET user`
		result = fireCommand(conn, getCmd)

		ja.Assertf(result.(string), `{"age":30,"name":"John"}`)
	})

	t.Run("Set and Get Nested JSON", func(t *testing.T) {
		setCmd := `JSON.SET user:2 $ {"name":"Alice","address":{"city":"New York","zip":"10001"},"array":[1,2,3,4,5]}`
		result := fireCommand(conn, setCmd)
		assert.Equal(t, "OK", result)

		getCmd := `JSON.GET user:2`
		result = fireCommand(conn, getCmd)
		ja.Assertf(result.(string), `{"name":"Alice","address":{"city":"New York","zip":"10001"},"array":[1,2,3,4,5]}`)
	})

	t.Run("Set and Get JSON Array", func(t *testing.T) {
		setCmd := `JSON.SET numbers $ [1,2,3,4,5]`
		result := fireCommand(conn, setCmd)
		assert.Equal(t, "OK", result)

		getCmd := `JSON.GET numbers`
		result = fireCommand(conn, getCmd)
		ja.Assertf(result.(string), `[1,2,3,4,5]`)
	})

	t.Run("Set and Get JSON with Special Characters", func(t *testing.T) {
		setCmd := `JSON.SET special $ {"key":"value with spaces","emoji":"😀"}`
		result := fireCommand(conn, setCmd)
		assert.Equal(t, "OK", result)

		getCmd := `JSON.GET special`
		result = fireCommand(conn, getCmd)

Review comment (suggestion):
It's better to store the JSON string representation being set and later used for assertion in a single variable and then use the variable in both places.
This improves maintainability and readability.

Code after:
			name:     "Set and Get Boolean True",
			setCmd:   `JSON.SET booleanTrue $ true`,
			getCmd:   `JSON.GET booleanTrue`,
			expected: "true",
		},
		{
			name:     "Set and Get Boolean False",
			setCmd:   `JSON.SET booleanFalse $ false`,
			getCmd:   `JSON.GET booleanFalse`,
			expected: "false",
		},
		{
			name:     "Set and Get Simple JSON",
			setCmd:   `JSON.SET user $ ` + simpleJSON,
			getCmd:   `JSON.GET user`,
			expected: simpleJSON,
		},
		{
			name:     "Set and Get Nested JSON",
			setCmd:   `JSON.SET user:2 $ ` + nestedJSON,
			getCmd:   `JSON.GET user:2`,
			expected: nestedJSON,
		},
		{
			name:     "Set and Get JSON Array",
			setCmd:   `JSON.SET numbers $ [1,2,3,4,5]`,
			getCmd:   `JSON.GET numbers`,
			expected: `[1,2,3,4,5]`,
		},
		{
			name:     "Set and Get JSON with Special Characters",
			setCmd:   `JSON.SET special $ ` + specialCharsJSON,
			getCmd:   `JSON.GET special`,
			expected: specialCharsJSON,
		},
		{
			name:     "Set Invalid JSON",
			setCmd:   `JSON.SET invalid $ {invalid:json}`,
			getCmd:   ``,
			expected: "ERR invalid JSON",
		},
		{
			name:     "Set JSON with Wrong Number of Arguments",
			setCmd:   `JSON.SET`,
			getCmd:   ``,
			expected: "ERR wrong number of arguments for 'JSON.SET' command",
		},
		{
			name:     "Get JSON with Wrong Number of Arguments",
			setCmd:   ``,
			getCmd:   `JSON.GET`,