Skip to content

json2.decoder2: cannot decode escaped string value #24834

Description

@gechandesu
V version: V 0.4.11 3271c72, press to see full `v doctor` output
V full version V 0.4.11 89d1aac.3271c72
OS linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P
Memory 1.57GB/15.35GB
V executable /home/ge/.vlang/v
V last modified time 2025-07-02 13:14:42
V home dir OK, value: /home/ge/.vlang
VMODULES OK, value: /home/ge/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /tmp
Git version git version 2.50.0
V git status weekly.2025.16-385-g3271c728
.git/config present true
cc version cc (GCC) 15.1.1 20250425
gcc version gcc (GCC) 15.1.1 20250425
clang version clang version 20.1.6
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (GNU libc) 2.41

What did you do?
./v -g -o vdbg cmd/v && ./vdbg anon_struct_json2.v && anon_struct_json2

import x.json2
import x.json2.decoder2

enum Unit {
	byte
	kilobyte
	megabyte
	gigabyte
	terabyte
}

struct Disk {
	dev  string
	size struct {
		value u64
		unit  Unit
	}
}

fn main() {
	disk := Disk{
		dev:  '/dev/sda'
		size: struct {
			value: 1000000
			unit:  .byte
		}
	}
	disk_str := json2.encode[Disk](disk)
	dump(disk_str)
	disk_dec := decoder2.decode[Disk](disk_str)!
	dump(disk_dec)

	assert disk == disk_dec
}

What did you see?

[anon_struct_json2.v:29] disk_str: {"dev":"\/dev\/sda","size":{"value":1000000,"unit":0}}
V panic: result not set (
{"dev":"\/d
          ^ invalid value. Unexpected character after string_ end)
v hash: 3271c72
/tmp/v_1000/anon_struct_json2.01JZ5MDBTAFD6DF03H077FZGAN.tmp.c:5981: at _v_panic: Backtrace
/tmp/v_1000/anon_struct_json2.01JZ5MDBTAFD6DF03H077FZGAN.tmp.c:5943: by panic_result_not_set
/tmp/v_1000/anon_struct_json2.01JZ5MDBTAFD6DF03H077FZGAN.tmp.c:14398: by main__main
/tmp/v_1000/anon_struct_json2.01JZ5MDBTAFD6DF03H077FZGAN.tmp.c:14465: by main

What did you expect to see?

string decoded as '/dev/sda'

Disk{
    dev: '/dev/sda'
    size: struct {
        value: 1000000
        unit: byte
    }
}

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions