Package org.jlab.utils
Class JsonUtils
java.lang.Object
org.jlab.utils.JsonUtils
Stuff to read and manipulate HIPO banks with JSON objects.
- Author:
- baltzell
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.jlab.jnp.utils.json.JsonObject
add
(org.jlab.jnp.utils.json.JsonObject a, org.jlab.jnp.utils.json.JsonObject b) JsonObject's merge method overwrites keys of the same name, this extends.static DataBank
Convenience method to create a bank containing a JsonObject.static DataBank
Convenience method to create a bank containing a JsonObject.static DataBank
Convenience method to create a bank containing a JsonObject.static DataBank
Modify event by extending bank by merging new JSON data to existing.static DataBank
extend
(DataEvent event, String bankName, String varName, org.jlab.jnp.utils.json.JsonObject extension) Modify event by extending bank by merging new JSON data to existing.static DataBank
Modify event by extending bank by merging new JSON data to existing.static DataBank
This won't be useful once DataBank.setByte(String,byte[]) is implementedstatic org.jlab.jnp.utils.json.JsonObject
JSON2Json
(org.json.JSONObject json) Convert from Map to JNP's JsonObjectstatic void
static org.jlab.jnp.utils.json.JsonObject
Convert a map to JNP's JsonObject WARNING: presumably not generic to extended JSONs, but sufficient for configuration sections of CLARA YAMLs.static org.jlab.jnp.utils.json.JsonObject
Convenience method to get a JsonObject from a bank.static org.jlab.jnp.utils.json.JsonObject
static void
Just print it to the screen, nicely.static void
Just print it to the screen, nicely.static void
show
(org.jlab.jnp.utils.json.JsonObject json) Just print it to the screen, nicely.static void
show
(org.json.JSONObject json) Just print it to the screen, nicely.
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
show
public static void show(org.jlab.jnp.utils.json.JsonObject json) Just print it to the screen, nicely.- Parameters:
json
-
-
show
public static void show(org.json.JSONObject json) Just print it to the screen, nicely.- Parameters:
json
-
-
show
Just print it to the screen, nicely.- Parameters:
bank
-varName
-
-
show
Just print it to the screen, nicely.- Parameters:
bank
-varName
-
-
read
Convenience method to get a JsonObject from a bank.- Parameters:
bank
- bank to readvarName
- name of byte variable to read- Returns:
- JSON generated from array of bytes
-
read
public static org.jlab.jnp.utils.json.JsonObject read(org.jlab.jnp.hipo4.data.Bank bank, String varName) -
fill
This won't be useful once DataBank.setByte(String,byte[]) is implemented- Parameters:
bank
- bank to modifyvarName
- name of bank byte variable to modifycontents
- contents of the variable, one byte per row- Returns:
- the input bank after modification
-
Map2Json
Convert a map to JNP's JsonObject WARNING: presumably not generic to extended JSONs, but sufficient for configuration sections of CLARA YAMLs.- Parameters:
map
-- Returns:
-
JSON2Json
public static org.jlab.jnp.utils.json.JsonObject JSON2Json(org.json.JSONObject json) Convert from Map to JNP's JsonObject- Parameters:
json
- an org.json.JSONObject- Returns:
- the corresponding org.jlab.jnp.utils.json.JsonObject
-
create
public static DataBank create(DataEvent event, String bankName, String varName, org.jlab.jnp.utils.json.JsonObject json) Convenience method to create a bank containing a JsonObject.- Parameters:
event
- event used to generate the bankbankName
- name of bank to createvarName
- name of variable to put the JSON object injson
- contents for the variable- Returns:
- new bank
-
create
public static DataBank create(DataEvent event, String bankName, String varName, org.json.JSONObject json) Convenience method to create a bank containing a JsonObject.- Parameters:
event
- event used to generate the bankbankName
- name of bank to createvarName
- name of variable to put the JSON object injson
- contents for the variable- Returns:
- new bank
-
create
Convenience method to create a bank containing a JsonObject.- Parameters:
event
- event used to generate the bankbankName
- name of bank to createvarName
- name of variable to put the JSON object injson
- contents for the variable- Returns:
- new bank
-
add
public static org.jlab.jnp.utils.json.JsonObject add(org.jlab.jnp.utils.json.JsonObject a, org.jlab.jnp.utils.json.JsonObject b) JsonObject's merge method overwrites keys of the same name, this extends. WARNING: presumably not generic to extended JSONs, but sufficient for configuration sections of CLARA YAMLs.- Parameters:
a
-b
-- Returns:
- a+b
-
extend
public static DataBank extend(DataEvent event, String bankName, String varName, org.jlab.jnp.utils.json.JsonObject extension) Modify event by extending bank by merging new JSON data to existing. If bank doesn't exist, create it.- Parameters:
event
- event to get the bank from and put it back intobankName
- name of bankvarName
- name of variable within bankextension
- JSON object to extend with- Returns:
-
extend
public static DataBank extend(DataEvent event, String bankName, String varName, org.json.JSONObject extension) Modify event by extending bank by merging new JSON data to existing. If bank doesn't exist, create it.- Parameters:
event
- event to get the bank from and put it back intobankName
- name of bankvarName
- name of variable within bankextension
- JSON object to extend with- Returns:
-
extend
public static DataBank extend(DataEvent event, String bankName, String varName, Map<String, Object> extension) Modify event by extending bank by merging new JSON data to existing. If bank doesn't exist, create it.- Parameters:
event
- event to get the bank from and put it back intobankName
- name of bankvarName
- name of variable within bankextension
- JSON object to extend with- Returns:
-
main
-