Skip to content

Get Started

Dannode36 edited this page Aug 7, 2024 · 1 revision

Basic Usage

json2x can be run from the command line with arguments or as a standalone executable to display its own CLI. The basic syntax for conversion is:

<path to JSON file> <language to convert to> <optional args> e.g. C:\Users\json2x\Documents\coolData.json cpp

This is all you need to begin converting your JSON data into code but there is more json2x can do...

Optional Arguments

Usage Explanation
-f Force json2x to output code regardless of possibly fatal errors
-p Throw an error if placeholders are present after code generation. Requires the output to be perfect
-l Some extra logging for debugging and nerds
-i <type> <num> The indent used for code generation (currently only supports "space" and "tab")
-o <directory> Custom output directory. The default is the working directory

Custom Formats

Template format

{
  "int32": "",
  "uint32": "",
  "int64": "",
  "uint64": "",
  "float32": "",
  "float64": "",
  "bool": "",
  "string": "",
  "placeholder": "",
  "var": "",
  "array": "",
  "structStart": "",
  "structEnd": "",
  "usingArray": "",
  "usingString": "",
  "extension": ""
}

C++ example

{
  "int32": "int",
  "uint32": "uint",
  "int64": "int64_t",
  "uint64": "uint64_t",
  "float32": "float",
  "float64": "double",
  "bool": "bool",
  "string": "string",
  "placeholder": "void*",
  "var": "{0} {1};",
  "array": "std::vector<{}>",
  "structStart": "struct {} {{",
  "structEnd": "};",
  "usingArray": "#include <vector>",
  "usingString": "#include <string>",
  "extension": "h"
}
Clone this wiki locally