1Dancer2::Serializer::JSUOsNe(r3)Contributed Perl DocumenDtaantcieorn2::Serializer::JSON(3)
2
3
4
6 Dancer2::Serializer::JSON - Serializer for handling JSON data
7
9 version 0.301004
10
12 This is a serializer engine that allows you to turn Perl data
13 structures into JSON output and vice-versa.
14
16 content_type
17 Returns 'application/json'
18
20 serialize($content)
21 Serializes a Perl data structure into a JSON string.
22
23 deserialize($content)
24 Deserializes a JSON string into a Perl data structure.
25
27 from_json($content, \%options)
28 This is an helper available to transform a JSON data structure to a
29 Perl data structures.
30
31 to_json($content, \%options)
32 This is an helper available to transform a Perl data structure to JSON.
33
34 Calling this function will not trigger the serialization's hooks.
35
36 Configuring the JSON Serializer using "set engines"
37 The JSON serializer options can be configured via "set engines". The
38 most common settings are:
39
40 allow_nonref
41 Ignore non-ref scalars returned from handlers. With this set the
42 "Hello, World!" handler returning a string will be dealt with
43 properly.
44
45 Set engines should be called prior to setting JSON as the serializer:
46
47 set engines =>
48 {
49 serializer =>
50 {
51 JSON =>
52 {
53 allow_nonref => 1
54 },
55 }
56 };
57
58 set serializer => 'JSON';
59 set content_type => 'application/json';
60
61 Returning non-JSON data.
62 Handlers can return non-JSON via "send_as", which overrides the default
63 serializer:
64
65 get '/' =>
66 sub
67 {
68 send_as html =>
69 q{Welcome to the root of all evil...<br>step into my office.}
70 };
71
72 Any other non-JSON returned format supported by 'send_as' can be used.
73
75 Dancer Core Developers
76
78 This software is copyright (c) 2021 by Alexis Sukrieh.
79
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82
83
84
85perl v5.34.0 2021-07-22 Dancer2::Serializer::JSON(3)