Documentation

Una is developed by Una Technologies Limited

All rights reserved

© 2022 Una Technologies Limited

Print

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:

JsonValue has Key - Output
Previous Displaying Value with Related Key