code: def testArtifactJsonValue(self):
      # Construct artifact.
      my_artifact = _MyArtifact2()
      my_artifact.jsonvalue_string = "aaa"
      my_artifact.jsonvalue_dict = {"k1": ["v1", "v2", 333]}
      my_artifact.jsonvalue_int = 123
      my_artifact.jsonvalue_float = 3.14
      my_artifact.jsonvalue_list = ["a1", "2", 3, {"4": 5.0}]
      my_artifact.jsonvalue_null = None
      self.assertFalse(my_artifact.has_custom_property("customjson1"))
      self.assertFalse(my_artifact.has_custom_property("customjson2"))
      my_artifact.set_json_value_custom_property("customjson1", {})
      my_artifact.set_json_value_custom_property(
          "customjson2", ["a", "b", 3]
      )
      my_artifact.set_json_value_custom_property("customjson3", "xyz")
      my_artifact.set_json_value_custom_property("customjson4", 3.14)
      my_artifact.set_json_value_custom_property("customjson5", False)
  
      # Test that the JsonValue getters return the same values we just set
      self.assertEqual(my_artifact.jsonvalue_string, "aaa")
      self.assertEqual(
          my_artifact.jsonvalue_dict, {"k1": ["v1", "v2", 333]}
      )
      self.assertEqual(my_artifact.jsonvalue_int, 123)
      self.assertEqual(my_artifact.jsonvalue_float, 3.14)
      self.assertEqual(
          my_artifact.jsonvalue_list, ["a1", "2", 3, {"4": 5.0}]
      )
      self.assertIsNone(my_artifact.jsonvalue_null)
      self.assertEmpty(
          my_artifact.get_json_value_custom_property("customjson1")
      )
      self.assertEqual(
          my_artifact.get_json_value_custom_property("customjson2"),
          ["a", "b", 3],
      )
      self.assertEqual(
          my_artifact.get_json_value_custom_property("customjson3"),
          "xyz",
      )
      self.assertEqual(
          my_artifact.get_json_value_custom_property("customjson4"),
          3.14,
      )
      self.assertEqual(
          my_artifact.get_json_value_custom_property("customjson5"),
          False,
      )
      self.assertEqual(
          my_artifact.get_bool_custom_property("customjson5"), False
      )
      self.assertTrue(my_artifact.has_custom_property("customjson1"))
      self.assertTrue(my_artifact.has_custom_property("customjson2"))
  
      # Test string and proto serialization.
      self.assertEqual(
          textwrap.dedent(
              """\
          Artifact(artifact: properties {
            key: "jsonvalue_dict"
            value {
              struct_value {
                fields {
                  key: "k1"
                  value {
                    list_value {
                      values {
                        string_value: "v1"
                      }
                      values {
                        string_value: "v2"
                      }
                      values {
                        number_value: 333.0
                      }
                    }
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_float"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    number_value: 3.14
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_int"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    number_value: 123.0
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_list"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    list_value {
                      values {
                        string_value: "a1"
                      }
                      values {
                        string_value: "2"
                      }
                      values {
                        number_value: 3.0
                      }
                      values {
                        struct_value {
                          fields {
                            key: "4"
                            value {
                              number_value: 5.0
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_string"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    string_value: "aaa"
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson1"
            value {
              struct_value {
              }
            }
          }
          custom_properties {
            key: "customjson2"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    list_value {
                      values {
                        string_value: "a"
                      }
                      values {
                        string_value: "b"
                      }
                      values {
                        number_value: 3.0
                      }
                    }
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson3"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    string_value: "xyz"
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson4"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    number_value: 3.14
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson5"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    bool_value: false
                  }
                }
              }
            }
          }
          , artifact_type: name: "MyTypeName2"
          properties {
            key: "bool1"
            value: BOOLEAN
          }
          properties {
            key: "float1"
            value: DOUBLE
          }
          properties {
            key: "float2"
            value: DOUBLE
          }
          properties {
            key: "int1"
            value: INT
          }
          properties {
            key: "int2"
            value: INT
          }
          properties {
            key: "jsonvalue_dict"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_empty"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_float"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_int"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_list"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_null"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_string"
            value: STRUCT
          }
          properties {
            key: "proto1"
            value: PROTO
          }
          properties {
            key: "proto2"
            value: PROTO
          }
          properties {
            key: "string1"
            value: STRING
          }
          properties {
            key: "string2"
            value: STRING
          }
          )"""
          ),
          str(my_artifact),
      )
  
      copied_artifact = _MyArtifact2()
      copied_artifact.set_mlmd_artifact(my_artifact.mlmd_artifact)
  
      self.assertEqual(copied_artifact.jsonvalue_string, "aaa")
      self.assertEqual(
          json.dumps(copied_artifact.jsonvalue_dict),
          '{"k1": ["v1", "v2", 333.0]}',
      )
      self.assertEqual(copied_artifact.jsonvalue_int, 123.0)
      self.assertEqual(copied_artifact.jsonvalue_float, 3.14)
      self.assertEqual(
          json.dumps(copied_artifact.jsonvalue_list),
          '["a1", "2", 3.0, {"4": 5.0}]',
      )
      self.assertIsNone(copied_artifact.jsonvalue_null)
      self.assertIsNone(copied_artifact.jsonvalue_empty)
      self.assertEqual(
          json.dumps(
              copied_artifact.get_json_value_custom_property(
                  "customjson1"
              )
          ),
          "{}",
      )
      self.assertEqual(
          json.dumps(
              copied_artifact.get_json_value_custom_property(
                  "customjson2"
              )
          ),
          '["a", "b", 3.0]',
      )
      self.assertEqual(
          copied_artifact.get_string_custom_property("customjson2"), ""
      )
      self.assertEqual(
          copied_artifact.get_int_custom_property("customjson2"), 0
      )
      self.assertEqual(
          copied_artifact.get_float_custom_property("customjson2"), 0.0
      )
      self.assertEqual(
          json.dumps(
              copied_artifact.get_custom_property("customjson2")
          ),
          '["a", "b", 3.0]',
      )
      self.assertEqual(
          copied_artifact.get_json_value_custom_property("customjson3"),
          "xyz",
      )
      self.assertEqual(
          copied_artifact.get_string_custom_property("customjson3"),
          "xyz",
      )
      self.assertEqual(
          copied_artifact.get_custom_property("customjson3"), "xyz"
      )
      self.assertEqual(
          copied_artifact.get_json_value_custom_property("customjson4"),
          3.14,
      )
      self.assertEqual(
          copied_artifact.get_float_custom_property("customjson4"), 3.14
      )
      self.assertEqual(
          copied_artifact.get_int_custom_property("customjson4"), 3
      )
      self.assertEqual(
          copied_artifact.get_custom_property("customjson4"), 3.14
      )
  
      # Modify nested structure and check proto serialization reflects changes.
      copied_artifact.jsonvalue_dict["k1"].append({"4": "x"})
      copied_artifact.jsonvalue_dict["k2"] = "y"
      copied_artifact.jsonvalue_dict["k3"] = None
      copied_artifact.jsonvalue_int = None
      copied_artifact.jsonvalue_list.append([6, "7"])
      copied_artifact.get_json_value_custom_property("customjson1")[
          "y"
      ] = ["z"]
      copied_artifact.get_json_value_custom_property(
          "customjson2"
      ).append(4)
  
      self.assertEqual(
          textwrap.dedent(
              """\
          Artifact(artifact: properties {
            key: "jsonvalue_dict"
            value {
              struct_value {
                fields {
                  key: "k1"
                  value {
                    list_value {
                      values {
                        string_value: "v1"
                      }
                      values {
                        string_value: "v2"
                      }
                      values {
                        number_value: 333.0
                      }
                      values {
                        struct_value {
                          fields {
                            key: "4"
                            value {
                              string_value: "x"
                            }
                          }
                        }
                      }
                    }
                  }
                }
                fields {
                  key: "k2"
                  value {
                    string_value: "y"
                  }
                }
                fields {
                  key: "k3"
                  value {
                    null_value: NULL_VALUE
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_float"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    number_value: 3.14
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_list"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    list_value {
                      values {
                        string_value: "a1"
                      }
                      values {
                        string_value: "2"
                      }
                      values {
                        number_value: 3.0
                      }
                      values {
                        struct_value {
                          fields {
                            key: "4"
                            value {
                              number_value: 5.0
                            }
                          }
                        }
                      }
                      values {
                        list_value {
                          values {
                            number_value: 6.0
                          }
                          values {
                            string_value: "7"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          properties {
            key: "jsonvalue_string"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    string_value: "aaa"
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson1"
            value {
              struct_value {
                fields {
                  key: "y"
                  value {
                    list_value {
                      values {
                        string_value: "z"
                      }
                    }
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson2"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    list_value {
                      values {
                        string_value: "a"
                      }
                      values {
                        string_value: "b"
                      }
                      values {
                        number_value: 3.0
                      }
                      values {
                        number_value: 4.0
                      }
                    }
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson3"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    string_value: "xyz"
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson4"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    number_value: 3.14
                  }
                }
              }
            }
          }
          custom_properties {
            key: "customjson5"
            value {
              struct_value {
                fields {
                  key: "__value__"
                  value {
                    bool_value: false
                  }
                }
              }
            }
          }
          , artifact_type: name: "MyTypeName2"
          properties {
            key: "bool1"
            value: BOOLEAN
          }
          properties {
            key: "float1"
            value: DOUBLE
          }
          properties {
            key: "float2"
            value: DOUBLE
          }
          properties {
            key: "int1"
            value: INT
          }
          properties {
            key: "int2"
            value: INT
          }
          properties {
            key: "jsonvalue_dict"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_empty"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_float"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_int"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_list"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_null"
            value: STRUCT
          }
          properties {
            key: "jsonvalue_string"
            value: STRUCT
          }
          properties {
            key: "proto1"
            value: PROTO
          }
          properties {
            key: "proto2"
            value: PROTO
          }
          properties {
            key: "string1"
            value: STRING
          }
          properties {
            key: "string2"
            value: STRING
          }
          )"""
          ),
          str(copied_artifact),
      )
  
imports: import json
  import textwrap
  from unittest import mock
  from absl import logging
  import tensorflow
  from tfx.types import artifact
  from tfx.types import system_artifacts
  from tfx.types import value_artifact
  from tfx.utils import json_utils
  from google.protobuf import struct_pb2
  from google.protobuf import json_format
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 3 for calling the ArtifactTest obj's underlying member method code with example usage: obj.testArtifactJsonValue() without return types