In this lesson, you will learn how React Native uses JSON to translate information so that your JavaScript code can "talk" to the native mobile platform.
The Language Barrier
You already know that React Native runs your JavaScript code on a separate thread from the native UI (the "Host Platform"). Because these two environments speak different languages—JavaScript and either Java/Kotlin (Android) or Objective-C/Swift (iOS)—they cannot share memory directly. They are like two people standing in different rooms who can only communicate by passing notes through a slot in the wall, known as the Bridge.
The JSON Translator
Because the Bridge only accepts text, we cannot pass complex JavaScript objects or functions directly across it. Instead, every piece of data must be converted into JSON (JavaScript Object Notation).
When you ask React Native to update a component or read a sensor, the process looks like this:
- Serialization: Your JavaScript code bundles the data into a JSON string.
- The Trip: That JSON string travels across the Bridge.
- Deserialization: The native side receives the string, parses it back into a native data type (like a Dictionary in Swift or a Bundle in Java), and executes the requested command.
For example, if you want to set a button’s color, your JavaScript might trigger an instruction that looks like this serialized JSON:
{
"module": "UIManager",
"method": "updateView",
"args": [123, "backgroundColor", "#FF0000"]
}
Why it Matters
This serialization process is not free. Every time you send data across the Bridge, the system must spend time and memory converting objects to text and back again. If you send too much data, or send it too frequently (like during a high-speed animation), the "translation" time can cause the Bridge to become a bottleneck. This is why keeping data minimal and efficient is a core skill for building smooth React Native applications.
Key Takeaway: Since JavaScript and the native platform live in separate threads, data must be serialized into JSON strings to travel across the Bridge, a process that has a performance cost if used excessively.