Set a variable for the indent level. You meet ( - increase it, go to a new line, indent for each next line 4 * level (or how much you need there).
You meet ) - output it on a new line with the old indentation, reduce the variable by one.
Like that.
Sample code (clean it yourself):
char * s = R"aa('users'=(('id'=10; 'name'='Serge'; 'roles'=('visitor'; 'moderator' )); ('id'=11; 'name'='Biales' ); true ))aa"; void space(int level) { const int ident = 4; for(int i = 0; i < level * ident; ++i) cout << ' '; } int main(int argc, const char * argv[]) { int level = 0; for(char * c = s; *c; ++c) { switch(*c) { case '(': cout << '\n'; space(level++); cout << "(\n"; space(level); break; case ')': cout << '\n'; space(--level); cout << ')'; break; case '\n': cout << '\n'; space(level); break; default: cout << *c; } } }