# BaseApi (Basic APIs)

## asJSONPrettyString

Convert a map object to a json formatted string.

```
BaseApi.asJSONPrettyString(Object obj)
```

**Parameters**

```
obj:   the object (can be a hashmap)
```

**Sample Code**

```java
Map<String, Object> product = new HashMap<>();
product.put("productId", "11");
String strJson = BaseApi.asJSONPrettyString(product);
```

**Returns**

```
the formatted string​
```

## asJSONString

Convert map object to a json string​ without formatting.

```
BaseApi.asJSONString(Object obj)
```

**Parameters**

```
obj:  object
```

**Sample Code**

```java
Map<String, Object> product = new HashMap<>();
product.put("productId", "11");
String strJson = BaseApi.asJSONString(product);
```

**Returns**

```
the json string​
```

## fromJSONString

Convert a json string​ to a map object.

```
BaseApi.fromJSONString(String json)
```

**Parameters**

```
json:     string representation of json
```

**Sample Code**

```java
String jsonString = "{\n" +
      "    \"productId\": \"abc\"\n" +
      "}";
Map<String, Object> map = BaseApi.fromJSONString(jsonString);
```

**Returns**

```
constructed hashmap​
```

## fromJSONStringAsArray

Convert a json string​ as a linked hashmap. The map can be interpreted later on.

```
BaseApi.fromJSONStringAsArray(String json)
```

**Parameters**

```
json:    string representation of json
```

**Sample Code**

```java
String jsonString = "[\n" +
      "    {\n" +
      "    \"product\": \"abc\"\n" +
      "    }\n" +
      "]";
List<Map<String, Object>> mapList = BaseApi.fromJSONStringAsArray(jsonString);
```

**Returns**

```
the array of json objects
```

## readJSON

Read the JSON from a file name​ located in a specific directory. It is converted into an map object.

```
BaseApi.readJSON(String dir, String fileName)
```

**Parameters**

```
dir:    the directory
fileName:  name of the file
```

**Sample Code**

```java
Map<String, Object> map = BaseApi.readJSON("/tmp/folder1", "file.json");
```

**Returns**

```
json document object​
```

## writeJSON

Write a map object into a file​ located on a specific directory.

```
BaseApi.writeJSON(String dir, String fileName, Object obj)
```

**Parameters**

```
dir:         directory
fileName:    name of the file
obj:         json document object 
```

**Sample Code**

```java
    String jsonString = "[\n" +
      "    {\n" +
      "    \"product\": \"abc\"\n" +
      "    }\n" +
      "]";
    BaseApi.writeJSON("/tmp/folder1", "file.json", jsonString);
```

**Returns**

```
result of the operation​
```

## writePrettyJSON

Write a map object into a file​ located on a specific directory. The JSON information is a formatted inside the file.

```
BaseApi.writePrettyJSON(String dir, String fileName, Object obj)
```

**Parameters**

```
dir:          directory 
fileName:     name of the file 
obj:          json formatted document
```

**Sample Code**

```java
    String jsonString = "[\n" +
      "    {\n" +
      "    \"product\": \"abc\"\n" +
      "    }\n" +
      "]";
    BaseApi.writePrettyJSON("/tmp/folder1", "file.json", jsonString);
```

**Returns**

```
result of the operation​
```

## successResult

Build and return a successful result map object.​

```
BaseApi.successResult()
or
BaseApi.successResult(String msg)
or
BaseApi.successResult(String msg, Object data)
```

**Parameters**

```
msg        message to be sent
data 
```

**Sample Code**

```java
BaseApi.successResult("Successfully added records");
```

**Returns**

```
result of the operation​
```

## errorResult

Build and return an error result map object.​

```
BaseApi.errorResult(String msg)
or
BaseApi.errorResult(String msg, int code)
```

**Parameters**

```
msg:     message to be sent
code:    return code
```

**Sample Code**

```java
BaseApi.errorResult("Failed to process records");
```

**Returns**

```
the result of the operation​
```

## extractMessage

Extract the message from the result object​. The result object has a detailed message in it therefore it will be returned.

```
BaseApi.extractMessage(Object obj)
```

**Parameters**

```
obj:     object as a hashmap
```

**Returns**

```
message string​
```

## isResult

Checking whether the object is a result object​.

```
BaseApi.isResult(Object obj)
```

**Parameters**

```
obj:    the object as a hashmap
```

**Sample Code**

```java
Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResult(res);
```

**Returns**

```
status of the result​
```

## isResultOrNull

Checking if result object is a valid one or a just a NuLL

```
BaseApi.isResultOrNull(Object obj)
```

**Parameters**

```
obj:    the object as a hashmap
```

**Sample Code**

```java
Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResultOrNull(res);
```

**Returns**

```
the status of the result​
```

## UUID

Generate a UUID sequence.

```
BaseApi.UUID()
```

**Parameters**

```
none​
```

**Sample Code**

```java
String uuid = BaseApi.UUID();
```

**Returns**

```
the uuid​
```

## uidToClassName

Extract class name​ from an input string.

```
BaseApi.uidToClassName(String uid)
```

**Parameters**

```
uid:    the className id
```

**Returns**

```
the class name​
```

## uidToId

Extract an long id number from a string UID.

```
BaseApi.uidToId(String uid)
```

**Parameters**

```
uid: 
```

**Returns**

```
gives id
```

## uidToIdStr

Retrieves​ the ID as a string from uid.

```
BaseApi.uidToIdStr(String uid) 
```

**Parameters**

```
uid: 
```

**Returns**

```
gives id in str
```

## waitForMillis

Wait for certain MS​ given as a long number. It is a blocking function call.

```
BaseApi.waitForMillis(long tm) 
```

**Parameters**

```
tm: 
```

**Sample Code**

```java
Result res = BaseApi.waitForMillis(10);
```

**Returns**

```
waits for given time
```

## remoteCall

// Basic Description //

<pre><code><strong>BaseApi.remoteCall(String javaClassName, String javaMethodName, Object... args)
</strong></code></pre>

**Parameters**

```
javaClassName
javaMethodName
```

**Sample Code**

```java
Object res = remoteCall("DSApi", "get", "shared.common.product", "12);
```

**Returns**

```
execute the call
```

## remoteCallAsResult

// Description //

```
BaseApi.remoteCallAsResult(String javaClassName, String javaMethodName, Object... args)
```

#### Parameters

```
javaClassName
javaMethodName
```

**Sample Code**

```java
Result res = remoteCallAsResult("BigQueryApi", "executeQuery", "SELECT ID FROM product_tbl");
```

**Returns**

```
// Some code
```

## remoteCallAsMap

// Description //

```
BaseApi.remoteCallAsMap(String javaClassName, String javaMethodName, Object... args)
```

#### Parameters

```
javaClassName
javaMethodName
```

**Sample Code**

```java
Map<String, Object> res =  remoteCallAsMap("UMApi", "getCurrentUser");
```

**Returns**

```
// Some code
```

## remoteCallAsString

// Description //

```
BaseApi.remoteCallAsString(String javaClassName, String javaMethodName, Object... args)
```

#### Parameters

```
javaClassName
javaMethodName
```

**Sample Code**

```java
String res = remoteCallAsString("GCPRestApi", "getProjectId");
```

**Returns**

```
// Some code
```

## remoteCallAsList

// Description //

```
BaseApi.remoteCallAsList(String javaClassName, String javaMethodName, Object... args)
```

#### Parameters

```
javaClassName
javaMethodName
```

#### Returns

```
// Some code
```

## remoteCallAsListOfMaps

// Description //&#x20;

```
BaseApi.remoteCallAsListOfMaps(String javaClassName, String javaMethodName, Object... args)
```

#### Parameters

```
javaClassName
javaMethodName
```

#### Returns

```
// Some code
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trillo.gitbook.io/trillo-workbench-java-sdk/json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
