MCPcopy
hub / github.com/tidwall/gjson / revSquash

Function revSquash

gjson.go:3372–3418  ·  view source on GitHub ↗
(json string)

Source from the content-addressed store, hash-verified

3370}
3371
3372func revSquash(json string) string {
3373 // reverse squash
3374 // expects that the tail character is a ']' or '}' or ')' or '"'
3375 // squash the value, ignoring all nested arrays and objects.
3376 i := len(json) - 1
3377 var depth int
3378 if json[i] != '"' {
3379 depth++
3380 }
3381 if json[i] == '}' || json[i] == ']' || json[i] == ')' {
3382 i--
3383 }
3384 for ; i >= 0; i-- {
3385 switch json[i] {
3386 case '"':
3387 i--
3388 for ; i >= 0; i-- {
3389 if json[i] == '"' {
3390 esc := 0
3391 for i > 0 && json[i-1] == '\\' {
3392 i--
3393 esc++
3394 }
3395 if esc%2 == 1 {
3396 continue
3397 }
3398 i += esc
3399 break
3400 }
3401 }
3402 if depth == 0 {
3403 if i < 0 {
3404 i = 0
3405 }
3406 return json[i:]
3407 }
3408 case '}', ']', ')':
3409 depth++
3410 case '{', '[', '(':
3411 depth--
3412 if depth == 0 {
3413 return json[i:]
3414 }
3415 }
3416 }
3417 return json
3418}
3419
3420// Paths returns the original GJSON paths for a Result where the Result came
3421// from a simple query path that returns an array, like:

Callers 2

TestRevSquashFunction · 0.85
PathMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestRevSquashFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…