v2 / vlib / x / json2 / encoder.v
43 lines · 37 sloc · 1.29 KB · 3ffc951cf555dc4818309a507ccb9d0da4de748f
Raw
1// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module json2
5
6// encode_pretty ...
7@[deprecated: 'use `encode(..., prettify: true)` instead']
8@[deprecated_after: '2025-10-30']
9pub fn encode_pretty[T](typed_data T) string {
10 return encode(typed_data, prettify: true)
11}
12
13// str returns the JSON string representation of the `map[string]Any` type.
14pub fn (f map[string]Any) str() string {
15 return Any(f).json_str()
16}
17
18// str returns the JSON string representation of the `[]Any` type.
19pub fn (f []Any) str() string {
20 return Any(f).json_str()
21}
22
23// str returns the string representation of the `Any` type. Use the `json_str` method.
24// If you want to use the escaped str() version of the `Any` type.
25pub fn (f Any) str() string {
26 if f is string {
27 return f
28 } else {
29 return f.json_str()
30 }
31}
32
33// json_str returns the JSON string representation of the `Any` type.
34pub fn (f Any) json_str() string {
35 return encode(f)
36}
37
38// prettify_json_str returns the pretty-formatted JSON string representation of the `Any` type.
39@[deprecated: 'use `encode(Any(...), prettify: true)` instead']
40@[deprecated_after: '2025-10-30']
41pub fn (f Any) prettify_json_str() string {
42 return encode(f, prettify: true)
43}
44