diff --git a/src/Context.php b/src/Context.php
index 9f752476..6924423b 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -124,6 +124,8 @@ final class Context
')' => 16,
'.' => 16,
',' => 16,
+ '->' => 16,
+ '->>' => 16,
';' => 16,
];
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index 67214f2b..5c9e011d 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -518,12 +518,15 @@ public function formatList(TokensList $list): string
} elseif (
$prev->keyword === 'DELIMITER'
|| ! (
- ($prev->type === TokenType::Operator && ($prev->value === '.' || $prev->value === '('))
- // No space after . (
+ ($prev->type === TokenType::Operator
+ && ($prev->value === '.' || $prev->value === '('
+ || $prev->value === '->' || $prev->value === '->>'))
+ // No space after punctuation and JSON operators.
|| ($curr->type === TokenType::Operator
&& ($curr->value === '.' || $curr->value === ','
- || $curr->value === '(' || $curr->value === ')'))
- // No space before . , ( )
+ || $curr->value === '(' || $curr->value === ')'
+ || $curr->value === '->' || $curr->value === '->>'))
+ // No space before punctuation and JSON operators.
|| $curr->type === TokenType::Delimiter && mb_strlen((string) $curr->value, 'UTF-8') < 2
)
) {
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index 557676fa..c492ce0e 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -317,6 +317,21 @@ public static function formatQueriesProviders(): array
'WHERE
' .
' 1',
],
+ 'json operator' => [
+ 'query' => 'SELECT details->\'$."first_name"\' FROM users',
+ 'text' => 'SELECT' . "\n" .
+ ' details->\'$."first_name"\'' . "\n" .
+ 'FROM' . "\n" .
+ ' users',
+ 'cli' => "\x1b[35mSELECT\n" .
+ " \x1b[39mdetails->\x1b[91m'$.\"first_name\"'\n" .
+ "\x1b[35mFROM\n" .
+ " \x1b[39musers\x1b[0m",
+ 'html' => 'SELECT
' .
+ ' details->\'$."first_name"\'
' .
+ 'FROM
' .
+ ' users',
+ ],
'typical' => [
'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or ' .
'id = 1 group by id order by id desc limit 1 offset 0',