Report Styles

Report Styles

Last Updated On October 21, 2019

The API Connector add-on for Google Sheets provides three report style options for converting JSON responses into a tabular format for Google Sheets.

report-styles-img1

Let’s consider the following simplified example, with 2 orders each containing 2 products. The underlying JSON looks like this:

DEFAULT (SINGLE ROW)

The default (single row) report style will produce separate columns for the nested product data, each identified with a number. This ensures that all values can be associated with their parent value (in this case, the order ID).

report-styles-img3

COMPACT

The compact report style will list all associated values in a single column, and will return data into the first available empty cell. This breaks the association with the parent element (the order ID) but is convenient when you’re primarily interested in counting, processing, or matching up elements within the nested line items themselves, since the data will be displayed in a single column rather than split among separate columns. It can also be useful if you’re NOT interested in those nested elements, since it will produce fewer columns to work around.

report-styles-img4

CONCATENATE

The concatenate report option will concatenate all the elements of each nested object together. This will produce a super-compact report with all nested elements in a single cell.

report-styles-img5

If you want to split pipe-separated cells back out again in Sheets, you can use a formula like this: =split(B2,”|”).

NOTES ON JSON CONVERSION TO SHEETS

JSON is a format for transferring text values using the following data structures:

  • Objects, which are un-ordered collections of name/value pairs. They start and end with curly braces, and each name/value pair is separated by a comma.
    Example: { “symbol”: “SPY”, “name”: “SPDR S&P 500”, “price”: 289.8 }
  • Arrays, which are ordered list of values. They start and end with brackets, and each value is separated by a comma.
    Example: [ { “symbol”: “SPY”, “name”: “SPDR S&P 500”, “price”: 289.8 }, { “symbol”: “AAPL”, “name”: “Apple Inc.”, “price”: 193.32 } ]

API Connector includes built-in ‘JSON to csv’ logic to flatten and convert these JSON responses into a tabular format for Google Sheets. However, some APIs are designed with formats that, say, nest all data objects into a parent object, or push keys and values into a single array. In those cases API Connector has no way to recognize which nested values are primary dimensions vs. attributes, so you may see values returned as separate columns when you’d prefer to see them as rows.

If you encounter this type of issue, you should experiment with the three provided report style algorithms to find the one that works best, and then leverage Sheets formulas to reconfigure the data as desired.

Comments:0

Leave a Reply

Your email address will not be published.