#String Parsing Logic for JSON UI

1 messages · Page 1 of 1 (latest)

chrome musk
#
"bindings": [

  /* ---------- #value1 ---------- */

  {
    "binding_type": "view",
    "source_property_name": "('a' + #text - 'hover_chat')",
    "target_property_name": "#f_text"
  },

  {
    "binding_type": "view",
    "source_property_name": "(#f_text - 'a')",
    "target_property_name": "#len1_num"
  },

  {
    "binding_type": "view",
    "source_property_name": "(('%.' + #len1_num + 's') * (#f_text - ('%.4s' * #f_text)))",
    "target_property_name": "#value1"
  },

  {
    "binding_type": "view",
    "source_property_name": "('a' + #f_text - ('%.4s' * #f_text) - #value1)",
    "target_property_name": "#rest1"
  },

  /* ---------- #value2 ---------- */

  {
    "binding_type": "view",
    "source_property_name": "(#rest1 - 'a')",
    "target_property_name": "#len2_num"
  },

  {
    "binding_type": "view",
    "source_property_name": "(('%.' + #len2_num + 's') * (#rest1 - ('%.4s' * #rest1)))",
    "target_property_name": "#value2"
  },

  {
    "binding_type": "view",
    "source_property_name": "('a' + #rest1 - ('%.4s' * #rest1) - #value2)",
    "target_property_name": "#rest2"
  },

  /* ---------- #value3 ---------- */

  {
    "binding_type": "view",
    "source_property_name": "(#rest2 - 'a')",
    "target_property_name": "#len3_num"
  },

  {
    "binding_type": "view",
    "source_property_name": "(('%.' + #len3_num + 's') * (#rest2 - ('%.4s' * #rest2)))",
    "target_property_name": "#value3"
  }

]

When working with Minecraft Bedrock UI JSON bindings, there is no native function for splitting strings or parsing dynamic segments.
To overcome this limitation, I implemented a length-based packed string format that allows multiple dynamic values to be safely transferred and decoded inside UI bindings.

Data Format

<prefix><len1><string1><len2><string2><len3><string3>...
ex: hover_chat003abc002de001f
-> value1: abc, value2: de, value3: f

All length fields must represent byte length, not character count.

This is critical because:

  • Bedrock UI string operations work on raw byte sequences
  • Multibyte characters (Korean, Chinese, emoji, etc.) will break character-based lengths

❌ Character length → causes corrupted parsing
✅ Byte length → always safe

"한" = 3 bytes (UTF-8)
"😊" = 4 bytes
hexed apex
#

this is very cool! But i feel it would be more effective to stack lengths at the start separated by some character, meaning if you want the last data packet you dont need to parse all the other lengths, a header if you will.

#

and instead of lengths, being a start and end index