JST: JSON tools  1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
Functions
JST_save.c File Reference
#include "jstools.h"
#include <stdio.h>
Include dependency graph for JST_save.c:

Go to the source code of this file.

Functions

JST_Error JST_save_to_stream (FILE *stream, const JST_Element *root, unsigned indent)
 Save the JSON tree to a stream, pretty-printed. More...
 
JST_Error JST_save_to_file (const char *path, const JST_Element *root, unsigned indent)
 Save the JSON tree to a file, pretty-printed. More...
 
JST_Error JST_save_to_stream_compact (FILE *stream, const JST_Element *root)
 Save the JSON tree to a stream, as a single line of text, without whitespaces. More...
 
JST_Error JST_save_to_file_compact (const char *path, const JST_Element *root)
 Save the JSON tree to a file, as a single line of text, without whitespaces. More...
 

Function Documentation

◆ JST_save_to_file()

JST_Error JST_save_to_file ( const char *  filepath,
const JST_Element root,
unsigned  indent 
)

Save the JSON tree to a file, pretty-printed.

Parameters
filepaththe path of the target file
rootthe root of the tree to save
indentthe amout of space to pretty print the tree.

Definition at line 56 of file JST_save.c.

56  {
57  if(( path == NULL )||( root == NULL )) {
58  return JST_ERR_NULL_ARGUMENT;
59  }
60  FILE * stream = fopen( path, "wt" );
61  if( stream == NULL ) {
62  return JST_ERR_ERRNO;
63  }
64  return JST_save_to_stream( stream, root, indent );
65 }
strerror() or perror() can be used to show the operating system layer error
Definition: jstools.h:112
JST_Error JST_save_to_stream(FILE *stream, const JST_Element *root, unsigned indent)
Save the JSON tree to a stream, pretty-printed.
Definition: JST_save.c:47
Function misused.
Definition: jstools.h:110
Here is the call graph for this function:

◆ JST_save_to_file_compact()

JST_Error JST_save_to_file_compact ( const char *  filepath,
const JST_Element root 
)

Save the JSON tree to a file, as a single line of text, without whitespaces.

Parameters
filepaththe path of the target file
rootthe root of the tree to save

Definition at line 120 of file JST_save.c.

120  {
121  if(( path == NULL )||( root == NULL )) {
122  return JST_ERR_NULL_ARGUMENT;
123  }
124  FILE * stream = fopen( path, "wt" );
125  if( stream == NULL ) {
126  return JST_ERR_ERRNO;
127  }
128  return JST_save_to_stream_compact( stream, root );
129 }
JST_Error JST_save_to_stream_compact(FILE *stream, const JST_Element *root)
Save the JSON tree to a stream, as a single line of text, without whitespaces.
Definition: JST_save.c:112
strerror() or perror() can be used to show the operating system layer error
Definition: jstools.h:112
Function misused.
Definition: jstools.h:110
Here is the call graph for this function:

◆ JST_save_to_stream()

JST_Error JST_save_to_stream ( FILE *  stream,
const JST_Element root,
unsigned  indent 
)

Save the JSON tree to a stream, pretty-printed.

Parameters
streamthe target stream.
rootthe root of the tree to save.
indentthe amout of space to pretty print the tree.

Definition at line 47 of file JST_save.c.

47  {
48  if(( stream == NULL )||( root == NULL )) {
49  return JST_ERR_NULL_ARGUMENT;
50  }
51  save_element( root, stream, 0, indent );
52  fprintf( stream, "\n" );
53  return fclose( stream ) ? JST_ERR_ERRNO : JST_ERR_NONE;
54 }
strerror() or perror() can be used to show the operating system layer error
Definition: jstools.h:112
Function misused.
Definition: jstools.h:110
Here is the caller graph for this function:

◆ JST_save_to_stream_compact()

JST_Error JST_save_to_stream_compact ( FILE *  stream,
const JST_Element root 
)

Save the JSON tree to a stream, as a single line of text, without whitespaces.

Parameters
filepaththe path of the target file
rootthe root of the tree to save

Definition at line 112 of file JST_save.c.

112  {
113  if(( stream == NULL )||( root == NULL )) {
114  return JST_ERR_NULL_ARGUMENT;
115  }
116  save_element_compact( root, stream );
117  return fclose( stream ) ? JST_ERR_ERRNO : JST_ERR_NONE;
118 }
strerror() or perror() can be used to show the operating system layer error
Definition: jstools.h:112
Function misused.
Definition: jstools.h:110
Here is the caller graph for this function: