diff --git a/vlib/json/json_test.v b/vlib/json/json_test.v index c1e875b3b0..dee0c6bdd6 100644 --- a/vlib/json/json_test.v +++ b/vlib/json/json_test.v @@ -160,7 +160,7 @@ fn test_struct_in_struct() { fn test_encode_map() { expected := '{"one":1,"two":2,"three":3,"four":4}' - numbers := { + numbers := map{ 'one': 1 'two': 2 'three': 3 @@ -172,7 +172,7 @@ fn test_encode_map() { } fn test_parse_map() { - expected := { + expected := map{ 'one': 1 'two': 2 'three': 3 @@ -180,7 +180,7 @@ fn test_parse_map() { } out := json.decode(map[string]int, '{"one":1,"two":2,"three":3,"four":4}') or { assert false - r := { + r := map{ '': 0 } r @@ -201,18 +201,14 @@ fn test_nested_type() { countries: [ Country{ name: 'UK' - cities: [City{'London'}, - City{'Manchester'}, - ] + cities: [City{'London'}, City{'Manchester'}] }, Country{ name: 'KU' - cities: [City{'Donlon'}, - City{'Termanches'}, - ] + cities: [City{'Donlon'}, City{'Termanches'}] }, ] - users: { + users: map{ 'Foo': User{ age: 10 nums: [1, 2, 3] @@ -230,14 +226,14 @@ fn test_nested_type() { pets: 'little boo' } } - extra: { - '2': { + extra: map{ + '2': map{ 'n1': 2 'n2': 4 'n3': 8 'n4': 16 } - '3': { + '3': map{ 'n1': 3 'n2': 9 'n3': 27 @@ -379,3 +375,14 @@ fn test_decode_null_object() { assert '$info.items' == '[]' assert '$info.maps' == '{}' } + +struct Foo2 { + name string +} + +fn test_pretty() { + foo := Foo2{'Bob'} + assert json.encode_pretty(foo) == '{ + "name": "Bob" +}' +} diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 4a38a477a8..23505b273a 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -629,7 +629,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { is_json_encode := name == 'json.encode' is_json_encode_pretty := name == 'json.encode_pretty' is_json_decode := name == 'json.decode' - g.is_json_fn = is_json_encode || is_json_decode + g.is_json_fn = is_json_encode || is_json_encode_pretty || is_json_decode mut json_type_str := '' mut json_obj := '' if g.is_json_fn {