gi-json-1.0.2: JSON GObject bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Json.Objects.Generator

Description

JsonGenerator provides an object for generating a JSON data stream from a tree of [structjson.Node] instances, and put it into a buffer or a file.

Synopsis

Exported types

newtype Generator Source #

Memory-managed wrapper type.

Instances

Instances details
Eq Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

GObject Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

ManagedPtrNewtype Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

TypedObject Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

Methods

glibType :: IO GType #

HasParentTypes Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

IsGValue (Maybe Generator) Source #

Convert Generator to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Json.Objects.Generator

type ParentTypes Generator Source # 
Instance details

Defined in GI.Json.Objects.Generator

class (GObject o, IsDescendantOf Generator o) => IsGenerator o Source #

Type class for types which can be safely cast to Generator, for instance with toGenerator.

Instances

Instances details
(GObject o, IsDescendantOf Generator o) => IsGenerator o Source # 
Instance details

Defined in GI.Json.Objects.Generator

toGenerator :: (MonadIO m, IsGenerator o) => o -> m Generator Source #

Cast to Generator, for types for which this is known to be safe. For general casts, use castTo.

Methods

getIndent

generatorGetIndent Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> m Word32

Returns: the number of repetitions per indentation level

Retrieves the value set using [methodjson.Generator.set_indent].

Since: 0.14

getIndentChar

generatorGetIndentChar Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> m Char

Returns: the character to be used when indenting

Retrieves the value set using [methodjson.Generator.set_indent_char].

Since: 0.14

getPretty

generatorGetPretty Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> m Bool

Returns: TRUE if the generated JSON should be pretty-printed, and FALSE otherwise

Retrieves the value set using [methodjson.Generator.set_pretty].

Since: 0.14

getRoot

generatorGetRoot Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> m (Maybe Node)

Returns: the root node

Retrieves a pointer to the root node set using [methodjson.Generator.set_root].

Since: 0.14

new

generatorNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m Generator

Returns: the newly created generator instance

Creates a new JsonGenerator.

You can use this object to generate a JSON data stream starting from a data object model composed by [structjson.Node]s.

setIndent

generatorSetIndent Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> Word32

indentLevel: the number of repetitions of the indentation character that should be applied when pretty printing

-> m () 

Sets the number of repetitions for each indentation level.

Since: 0.14

setIndentChar

generatorSetIndentChar Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> Char

indentChar: a Unicode character to be used when indenting

-> m () 

Sets the character to be used when indenting.

Since: 0.14

setPretty

generatorSetPretty Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> Bool

isPretty: whether the generated string should be pretty printed

-> m () 

Sets whether the generated JSON should be pretty printed.

Pretty printing will use indentation character specified in the [propertyjson.Generator:indent-char] property and the spacing specified in the [propertyjson.Generator:indent] property.

Since: 0.14

setRoot

generatorSetRoot Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> Node

node: the root node

-> m () 

Sets the root of the JSON data stream to be serialized by the given generator.

The passed node is copied by the generator object, so it can be safely freed after calling this function.

toData

generatorToData Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> m (Text, Word64)

Returns: a newly allocated string holding a JSON data stream

Generates a JSON data stream from generator and returns it as a buffer.

toFile

generatorToFile Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> [Char]

filename: the path to the target file

-> m ()

(Can throw GError)

Creates a JSON data stream and puts it inside filename, overwriting the file's current contents.

This operation is atomic, in the sense that the data is written to a temporary file which is then renamed to the given filename.

toGstring

generatorToGstring Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a) 
=> a

generator: a generator

-> String

string: a string buffer

-> m String

Returns: the passed string, updated with the generated JSON data

Generates a JSON data stream and appends it to the string buffer.

Since: 1.4

toStream

generatorToStream Source #

Arguments

:: (HasCallStack, MonadIO m, IsGenerator a, IsOutputStream b, IsCancellable c) 
=> a

generator: a generator

-> b

stream: the output stream used to write the JSON data

-> Maybe c

cancellable: a GCancellable

-> m ()

(Can throw GError)

Outputs JSON data and writes it (synchronously) to the given stream.

Since: 0.12

Properties

indent

Number of spaces to be used to indent when pretty printing.

constructGeneratorIndent :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “indent” property. This is rarely needed directly, but it is used by new.

getGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> m Word32 Source #

Get the value of the “indent” property. When overloading is enabled, this is equivalent to

get generator #indent

setGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> Word32 -> m () Source #

Set the value of the “indent” property. When overloading is enabled, this is equivalent to

set generator [ #indent := value ]

indentChar

The character that should be used when indenting in pretty print.

Since: 0.6

constructGeneratorIndentChar :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “indent-char” property. This is rarely needed directly, but it is used by new.

getGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> m Word32 Source #

Get the value of the “indent-char” property. When overloading is enabled, this is equivalent to

get generator #indentChar

setGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> Word32 -> m () Source #

Set the value of the “indent-char” property. When overloading is enabled, this is equivalent to

set generator [ #indentChar := value ]

pretty

Whether the output should be "pretty-printed", with indentation and newlines.

The indentation level can be controlled by using the [propertyjson.Generator:indent] property.

constructGeneratorPretty :: (IsGenerator o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “pretty” property. This is rarely needed directly, but it is used by new.

getGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> m Bool Source #

Get the value of the “pretty” property. When overloading is enabled, this is equivalent to

get generator #pretty

setGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> Bool -> m () Source #

Set the value of the “pretty” property. When overloading is enabled, this is equivalent to

set generator [ #pretty := value ]

root

The root node to be used when constructing a JSON data stream.

Since: 0.4

constructGeneratorRoot :: (IsGenerator o, MonadIO m) => Node -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “root” property. This is rarely needed directly, but it is used by new.

getGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> m (Maybe Node) Source #

Get the value of the “root” property. When overloading is enabled, this is equivalent to

get generator #root

setGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> Node -> m () Source #

Set the value of the “root” property. When overloading is enabled, this is equivalent to

set generator [ #root := value ]