pianod2
multisource multiuser scriptable networked music player
Classes | Enumerations | Functions | Variables
json_format.cpp File Reference

JSON formatter A simple JSON formatter using the Parsnip library. More...

#include <cstdlib>
#include <unistd.h>
#include <istream>
#include <iostream>
#include <fstream>
#include "parsnip.h"
Include dependency graph for json_format.cpp:

Classes

struct  Options
 

Enumerations

enum class  Action {
  TIDY , VALIDATE , EXPLAIN , FLATTEN_W_DICT ,
  FLATTEN_W_MEMBERS
}
 

Functions

void setprogname (const char *name)
 
const char * getprogname (void)
 
void render_exception (const char *filename, const Parsnip::Exception &ex)
 Render a parsnip exception to standard error in a standard way. More...
 
Parsnip::Data read_json_file (const char *name, std::istream &src)
 Read a JSON document from a stream. More...
 
Parsnip::Data load_json_file (const char *name)
 Read in JSON from a file. More...
 
bool try_load_json_file (const char *name, Parsnip::Data &file_contents)
 Read in JSON from a file. More...
 
void flatten (const Parsnip::Data &data, Action action, const std::string varname)
 Reformat a JSON file into a series of assignments, perhaps for use with a shell script or diff. More...
 
bool process_file (const char *name, Parsnip::Data &data, const Options &options)
 Take action on a file. More...
 
void usage ()
 Display command-line usage statement. More...
 
int main (int argc, char *const *argv)
 

Variables

static const char * progname
 

Detailed Description

JSON formatter A simple JSON formatter using the Parsnip library.

Enumeration Type Documentation

◆ Action

enum Action
strong
Enumerator
TIDY 
VALIDATE 
EXPLAIN 
FLATTEN_W_DICT 
FLATTEN_W_MEMBERS 

Function Documentation

◆ flatten()

void flatten ( const Parsnip::Data data,
Action  action,
const std::string  varname 
)

Reformat a JSON file into a series of assignments, perhaps for use with a shell script or diff.

Parameters
dataThe data to reformat
actionEither FLATTEN_W_DICTIONARY or FLATTEN_W_MEMBERS.
varnameThe "variable" name to which options/array specifiers are appended.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getprogname()

const char* getprogname ( void  )
Here is the caller graph for this function:

◆ load_json_file()

Parsnip::Data load_json_file ( const char *  name)

Read in JSON from a file.

On error, exit with failure.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)
Here is the call graph for this function:

◆ process_file()

bool process_file ( const char *  name,
Parsnip::Data data,
const Options options 
)

Take action on a file.

Parameters
nameThe name of the file (for error reporting).
dataThe contents of the file.
optionsOptions and data for the action to be taken.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_json_file()

Parsnip::Data read_json_file ( const char *  name,
std::istream &  src 
)

Read a JSON document from a stream.

On error, exit with failure.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_exception()

void render_exception ( const char *  filename,
const Parsnip::Exception ex 
)

Render a parsnip exception to standard error in a standard way.

Parameters
filenameThe filename to which the exception pertains.
exThe exception.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setprogname()

void setprogname ( const char *  name)
Here is the caller graph for this function:

◆ try_load_json_file()

bool try_load_json_file ( const char *  name,
Parsnip::Data file_contents 
)

Read in JSON from a file.

Parameters
nameThe name of the file.
[out]file_contentsOn return, set to the parsed JSON.
Returns
True on success, false on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ usage()

void usage ( )

Display command-line usage statement.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ progname

const char* progname
static