code: def test_from_and_to_json_roundtrip(syntax_module):
      """Tests if the to_json and from_json (and by extension to_dict and from_dict)
      work for all examples in the Example Gallery.
      """
      for filename in iter_examples_filenames(syntax_module):
          source = pkgutil.get_data(syntax_module.__name__, filename)
          chart = eval_block(source)
  
          if chart is None:
              raise ValueError(
                  f"Example file {filename} should define chart in its final "
                  "statement."
              )
  
          try:
              first_json = chart.to_json()
              reconstructed_chart = alt.Chart.from_json(first_json)
              # As the chart objects are not
              # necessarily the same - they could use different objects to encode the same
              # information - we do not test for equality of the chart objects, but rather
              # for equality of the json strings.
              second_json = reconstructed_chart.to_json()
              assert first_json == second_json
          except Exception as err:
              raise AssertionError(
                  f"Example file {filename} raised an exception when "
                  f"doing a json conversion roundtrip: {err}"
              ) from err
  
file_path: altair/tests/test_examples.py
imports: import io
  import pkgutil
  import pytest
  import altair
  from altair.utils.execeval import eval_block
  from tests import examples_arguments_syntax
  from tests import examples_methods_syntax
label_desc: Use image node_id 3 for calling a global function with example usage: test_from_and_to_json_roundtrip(syntax_module) without return types