Design

Grouping

Group by any item of your data or change the orginal structure of the JSON data source
COMMUNITY FEATURE Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
  v5.0+  NEW

Group and sum

A custom iterator can be used to group rows based on the value of a specific attribute (in this case, brand).

Additionally, with aggregator formatters, you can sum quantities:

data
[
  { "brand":"Lucid"   , "qty":1  },
  { "brand":"Faraday" , "qty":4  },
  { "brand":"Venturi" , "qty":3  },
  { "brand":"Faraday" , "qty":2  },
  { "brand":"Aptera"  , "qty":1  },
  { "brand":"Lucid"   , "qty":10 }
]
template
VehiclesQuantity{d[brand].brand}{d[brand].qty:aggSum(.brand)}{d[brand+1].brand}
Carbone Merge Icon
result
VehiclesQuantityAptera1Faraday6Lucid11Venturi3

Transform the result of a database

Since 4.23.0+ with activated pre-release tag

Carbone can also transform the JSON with the :set formatter. More information here.

For example, if the JSON is a flat array coming directly from a database (MySQL, MariaDB, PostgreSQL, Oracle, MS SQL), Carbone can build a hierarchical JSON with just a few lines of code!

data
[
  { "country" : "France", "city" : "Paris" },
  { "country" : "France", "city" : "Nantes" },
  { "country" : "France", "city" : "Pouzauges" },
  { "country" : "Italy" , "city" : "Rome" },
  { "country" : "Italy" , "city" : "Venise" }
]
template
{d[].city:set(c.countries[id=.country].cities[].name)}{c.countries[i].id}{c.countries[i].cities[i].name}{c.countries[i].cities[i+1].name}{c.countries[i+1].id}
Carbone Merge Icon
result
FranceParisNantesPouzaugesItalyRomeVenise