Class JSONEditor
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.AbstractEditor
-
- edu.uiuc.ncsa.security.util.cli.json_edit.JSONEditor
-
public class JSONEditor extends AbstractEditor
An editor for JSON objects. Mostly an experiment to see if this is viable for large JSON objects.Created by Jeff Gaynor
on 8/17/20 at 10:26 AM
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSONEditor.formatRecord
-
Field Summary
Fields Modifier and Type Field Description static String
ADD_NODE
static String
CHANGE_NODE
static String
CURRENT_NODE
static String
DELETE_NODE
static String
FILE_FLAG
static String
FILE_LOAD
static String
FILE_SAVE
static String
FORMAT_TYPE_BOOLEAN
static String
FORMAT_TYPE_JSON_ARRAY
static String
FORMAT_TYPE_JSON_OBJECT
static String
FORMAT_TYPE_NULL
static String
FORMAT_TYPE_NUMBER
static String
FORMAT_TYPE_STRING
static String
FORMAT_TYPE_UNKNOWN
static String
LIST_NODE
static String
PRINT_RAW_FLAG
protected static int
RC_CONTINUE
protected static int
RC_EXIT
protected static int
RC_NO_OP
protected static int
RC_OK
static String
SET_NODE_VALUE
static String
TREE_COMMAND
protected String
TREE_PIPE
protected String
TREE_PLUS
protected static String
TYPE_FLAG
protected static String
VALUE_FLAG
-
Fields inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
HELP_COMMAND, isDone, PROMPT, QUIT_COMMAND, QUIT_COMMAND_LONG, VERBOSE_COMMAND, VERBOSE_COMMAND_LONG, verboseOn
-
-
Constructor Summary
Constructors Constructor Description JSONEditor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_doAddNode(EditorInputLine eil)
protected void
_doChangeNode(EditorInputLine eil)
protected void
_doCurrentNode()
protected int
_doFileSave(EditorInputLine eil)
protected int
_doListNode(EditorInputLine eil)
protected int
_doVerbose(EditorInputLine eil)
protected void
addNodeHelp()
protected Object
convertByType(String type, String rawValue)
void
execute()
protected net.sf.json.JSON
fileToJSON(String filename)
protected String
fileToString(String fileName)
protected String
formatScalar(Object object)
protected String
formatSingleEntry(String key, Object obj)
Entries look likenet.sf.json.JSON
getCurrentObject()
protected String
getEntryType(Object obj)
protected void
insertNode(net.sf.json.JSONObject json, net.sf.json.JSON node, String path)
protected void
listNodeHelp()
static void
main(String[] args)
protected net.sf.json.JSON
navigate(String[] path)
Navigates to the next to last component for a full path.protected void
printArrayTree(String indent, String nodeName, net.sf.json.JSONArray array)
protected void
printObjectTree(String indent, String nodeName, net.sf.json.JSONObject jsonObject)
protected void
printRecords(List<JSONEditor.formatRecord> formatRecordList, boolean rawOnly)
protected void
printTypes()
void
setCurrentObject(net.sf.json.JSON currentObject)
protected void
showFileSaveHelp()
protected void
writeToFile(String filename, String contents)
-
Methods inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
getIoInterface, readline, say, sayi, sayv, setIoInterface, showHelp, verboseHelp
-
-
-
-
Field Detail
-
CHANGE_NODE
public static final String CHANGE_NODE
- See Also:
- Constant Field Values
-
LIST_NODE
public static final String LIST_NODE
- See Also:
- Constant Field Values
-
CURRENT_NODE
public static final String CURRENT_NODE
- See Also:
- Constant Field Values
-
ADD_NODE
public static final String ADD_NODE
- See Also:
- Constant Field Values
-
DELETE_NODE
public static final String DELETE_NODE
- See Also:
- Constant Field Values
-
SET_NODE_VALUE
public static final String SET_NODE_VALUE
- See Also:
- Constant Field Values
-
TREE_COMMAND
public static final String TREE_COMMAND
- See Also:
- Constant Field Values
-
FILE_LOAD
public static final String FILE_LOAD
- See Also:
- Constant Field Values
-
FILE_SAVE
public static final String FILE_SAVE
- See Also:
- Constant Field Values
-
RC_CONTINUE
protected static int RC_CONTINUE
-
RC_EXIT
protected static int RC_EXIT
-
RC_OK
protected static int RC_OK
-
RC_NO_OP
protected static int RC_NO_OP
-
TREE_PIPE
protected String TREE_PIPE
-
TREE_PLUS
protected String TREE_PLUS
-
FILE_FLAG
public static final String FILE_FLAG
- See Also:
- Constant Field Values
-
TYPE_FLAG
protected static String TYPE_FLAG
-
VALUE_FLAG
protected static String VALUE_FLAG
-
PRINT_RAW_FLAG
public static final String PRINT_RAW_FLAG
- See Also:
- Constant Field Values
-
FORMAT_TYPE_JSON_OBJECT
public static final String FORMAT_TYPE_JSON_OBJECT
- See Also:
- Constant Field Values
-
FORMAT_TYPE_JSON_ARRAY
public static final String FORMAT_TYPE_JSON_ARRAY
- See Also:
- Constant Field Values
-
FORMAT_TYPE_BOOLEAN
public static final String FORMAT_TYPE_BOOLEAN
- See Also:
- Constant Field Values
-
FORMAT_TYPE_NUMBER
public static final String FORMAT_TYPE_NUMBER
- See Also:
- Constant Field Values
-
FORMAT_TYPE_STRING
public static final String FORMAT_TYPE_STRING
- See Also:
- Constant Field Values
-
FORMAT_TYPE_NULL
public static final String FORMAT_TYPE_NULL
- See Also:
- Constant Field Values
-
FORMAT_TYPE_UNKNOWN
public static final String FORMAT_TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentObject
public net.sf.json.JSON getCurrentObject()
-
setCurrentObject
public void setCurrentObject(net.sf.json.JSON currentObject)
-
execute
public void execute() throws Throwable
- Overrides:
execute
in classAbstractEditor
- Throws:
Throwable
-
showFileSaveHelp
protected void showFileSaveHelp()
-
writeToFile
protected void writeToFile(String filename, String contents) throws IOException
- Throws:
IOException
-
_doFileSave
protected int _doFileSave(EditorInputLine eil)
-
insertNode
protected void insertNode(net.sf.json.JSONObject json, net.sf.json.JSON node, String path)
-
fileToJSON
protected net.sf.json.JSON fileToJSON(String filename) throws IOException
- Throws:
IOException
-
fileToString
protected String fileToString(String fileName) throws IOException
- Throws:
IOException
-
printObjectTree
protected void printObjectTree(String indent, String nodeName, net.sf.json.JSONObject jsonObject)
-
printArrayTree
protected void printArrayTree(String indent, String nodeName, net.sf.json.JSONArray array)
-
addNodeHelp
protected void addNodeHelp()
-
_doAddNode
protected int _doAddNode(EditorInputLine eil)
-
listNodeHelp
protected void listNodeHelp()
-
navigate
protected net.sf.json.JSON navigate(String[] path)
Navigates to the next to last component for a full path. If this returns a null, then there was no such path- Parameters:
path
-- Returns:
-
_doListNode
protected int _doListNode(EditorInputLine eil)
-
_doCurrentNode
protected void _doCurrentNode()
-
_doVerbose
protected int _doVerbose(EditorInputLine eil)
-
_doChangeNode
protected void _doChangeNode(EditorInputLine eil)
-
main
public static void main(String[] args)
-
printTypes
protected void printTypes()
-
formatSingleEntry
protected String formatSingleEntry(String key, Object obj)
Entries look likekey | type | entry
types are+ = JSON object * = array b = boolean n = number s = string
- Parameters:
obj
-- Returns:
-
printRecords
protected void printRecords(List<JSONEditor.formatRecord> formatRecordList, boolean rawOnly)
-
-