This documentation details operations and conversions involving JSON values, including construction, data type validation, translation to arrays, and object manipulation within the JSON format.
JsonValue Construction
Translating the Screen Item to JsonValue
Convert to JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Json_toJsonValue\" disabled=\"true\" x=\"-22\" y=\"112\"/></xml>"}
This is used to convent the Screen Item to Json Value.
Parameters: Screen Item
Output: Json Value
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"Json_toJsonValue\"><value name=\"data\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"'{name\\\":\\\"Hello World\\\", \\\"Number\\\":255}'\"</field></block></value></block></value></block></value></block></statement></block></xml>"}
The output:
Translating the Text to JsonValue
Convert the content of string to JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Json_parse\" disabled=\"true\" x=\"-22\" y=\"157\"><value name=\"str\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
This is used to convent the String to JsonValue.
Parameters: String
Output: Json Value
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"{\\\"name\\\":\\\"Hello World\\\", \\\"Number\\\":255}\"</field></block></value></block></value></block></value></block></statement></block></xml>"}
The output:
Common JsonValue Operations
Checking Data Type of JsonValue
Json Value is
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_is\" disabled=\"true\" x=\"-67\" y=\"292\"><field name=\"type\">JsonValueDataType.String</field><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to check whether the Json Value is in correct type.
Parameters: Json Value
Condition: String (Default)/Number/Boolean/Array/Object/Null
Output: Boolean (True/False)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">45</field></shadow></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"Json_JsonValue_asNumber\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Json_JsonValue_is\"><field name=\"type\">JsonValueDataType.String</field><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><statement name=\"DO0\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"It is a String.\"</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"It is not a String.\"</field></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:
Translating the JsonValue to String
Json Value stringify
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_stringify\" disabled=\"true\" x=\"-22\" y=\"382\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to change the Json Value to String.
Parameters: Json Value
Output: String
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"{\\\"name\\\":\\\"Hello World\\\", \\\"Number\\\":255}\"</field></block></value></block></value></block></value></block></statement></block></xml>"}
The output:
JsonValue Validation
Json Value is valid
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_isValid\" disabled=\"true\" x=\"-22\" y=\"472\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to check whether the Json Value is valid.
Parameters: Json Value
Output: Boolean (True/False)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"{\\\"a\\\":1, \\\"b\\\": 3}\"</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Json_JsonValue_isValid\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><statement name=\"DO0\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"The Json Value is valid.\"</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"The Json Value is not valid.\"</field></block></value></block></statement></block></next></block></statement></block></xml>"}
The output:
Type Conversions
Translating JsonValue to JsonValue Array
Json Value as JsonValue array
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_asJsonValueArray\" disabled=\"true\" x=\"-22\" y=\"248\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to Json Value array.
Parameters: Json Value
Output: Json Value Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>jsonArray</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"[\\\"Hello\\\", \\\"World\\\"]\"</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">jsonArray</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asJsonValueArray\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">jsonArray</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">jsonArray</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Translating JsonValue to Boolean Array
Json Value as boolean array
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>jsonArray</variable><variable>index</variable></variables><block type=\"Json_JsonValue_asBooleanArray\" disabled=\"true\" x=\"-22\" y=\"652\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to Boolean array.
Parameters: Json Value
Output: Boolean Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>boolArray</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"[true, false, false, true]\"</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">boolArray</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asBooleanArray\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">boolArray</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">boolArray[index].toString()</field></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Translating JsonValue to Number Array
Json Value as number array
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>boolArray</variable><variable>index</variable></variables><block type=\"Json_JsonValue_asNumberArray\" disabled=\"true\" x=\"-22\" y=\"428\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to number array.
Parameters: Json Value
Output: Number Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>numArray</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"[1, 2, 3, 4]\"</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numArray</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asNumberArray\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">numArray</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">numArray[index].toString()</field></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Translating JsonValue to String Array
Json Value as string array
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>numArray</variable><variable>index</variable></variables><block type=\"Json_JsonValue_asStringArray\" disabled=\"true\" x=\"-22\" y=\"608\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to string array.
Parameters: Json Value
Output: String Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>stringArray</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">[\"Hello\",\"World\"]</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">stringArray</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asStringArray\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">stringArray</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">stringArray</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Checking JsonValue is True or False
Json Value as Boolean
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>stringArray</variable><variable>index</variable></variables><block type=\"Json_JsonValue_asBoolean\" disabled=\"true\" x=\"-22\" y=\"428\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to check Json Value is true or false.
Parameters: Json Value
Output: Boolean (True/False)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">true</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Json_JsonValue_asBoolean\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><statement name=\"DO0\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"This is TRUE.\"</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"This is FALSE.\"</field></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:
Translating JsonValue to Number
Json Value as number
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_asNumber\" disabled=\"true\" x=\"23\" y=\"202\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to number.
Parameters: Json Value
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>number</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">222</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">number</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asNumber\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"variables_get\"><field name=\"VAR\">number</field></block></value></block></next></block></next></block></statement></block></xml>"}
The output:
JsonValue as Number – Output
Json Value as string
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>number</variable></variables><block type=\"Json_JsonValue_asString\" disabled=\"true\" x=\"22\" y=\"473\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to convert the Json Value to string.
Parameters: Json Value
Output: String
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>string</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"\\\"Hello World\\\"\"</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">string</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_asString\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"variables_get\"><field name=\"VAR\">string</field></block></value></block></next></block></next></block></statement></block></xml>"}
The output:
Object Operations
Showing the Object in JsonValue Format
Json Value get values as JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>string</variable></variables><block type=\"Json_JsonValue_getValues\" disabled=\"true\" x=\"-22\" y=\"472\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to get the object of the Json Value to Json Value.
Parameters: Json Value (Object Operation)
Output: Json Value
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>getKeys</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">{\"name\":\"Hello World\", \"Number\":255}</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">getKeys</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_getKeys\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"text_join\"><mutation items=\"2\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">The keys are: </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">getKeys</field></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing Keys in String Array Format
Convert the content of string to JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>getKeys</variable></variables><block type=\"Json_JsonValue_getKeys\" disabled=\"true\" x=\"23\" y=\"517\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value></block></xml>"}
This is used to get keys of the Json Value to string array.
Parameters: Json Value (Object Operation)
Output: String Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>getKeys</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">{\"name\":\"Hello World\", \"Number\":255}</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">getKeys</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_JsonValue_getKeys\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"text_join\"><mutation items=\"2\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">The keys are: </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">getKeys</field></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Displaying Value with Related Key
JsonValue get value using key
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable><variable>getKeys</variable></variables><block type=\"Json_JsonValue_get\" disabled=\"true\" x=\"-22\" y=\"652\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value><value name=\"key\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
This is used to get the value using the object key.
Parameters: Json Value (Object Operation)
Output: Json Value Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">{\"name\":\"Hello World\", \"Number\":255}</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"Json_JsonValue_get\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value><value name=\"key\"><shadow type=\"text\"><field name=\"TEXT\">name</field></shadow></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}
The output:
Finding the Corresponding Key
JsonValue has key
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"Json_JsonValue_has\" disabled=\"true\" x=\"-22\" y=\"697\"><value name=\"jsonValue\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">jsonValue</field></block></value><value name=\"key\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
This is used to check whether the Json Value contains the corresponding key.
Parameters:
- Json Value (Object Operation)
- String
Output: Boolean (True/False)
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>jsonValue</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">jsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Json_parse\"><value name=\"str\"><shadow type=\"text\"><field name=\"TEXT\">{\"name\":\"Hello World\", \"Number\":255}</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Json_JsonValue_has\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">jsonValue</field></block></value><value name=\"key\"><shadow type=\"text\"><field name=\"TEXT\">name</field></shadow></value></block></value><statement name=\"DO0\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">The Json Value contains that key.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">The Json Value does not contain that key.</field></shadow></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:
Table of Content