Skip to main content
Glama

Fetch JSONPath MCP

by ackness
test_parse.py1.55 kB
import json import pytest from jsonrpc_mcp.utils import extract_json DEMO_STR = json.dumps( { "foo": [{"baz": 1, "qux": "a"}, {"baz": 2, "qux": "b"}], "bar": {"items": [10, 20, 30], "config": {"enabled": True, "name": "example", "nested": {"key1": "value1", "key2": "value2"}}}, "metadata": {"version": "1.0.0", "timestamp": "2023-01-01T00:00:00Z"}, } ) @pytest.mark.parametrize( "pattern,expected", [ ("foo[*].baz", [1, 2]), ("bar.items", [[10, 20, 30]]), ("bar.items[*]", [10, 20, 30]), ("bar.config.enabled", [True]), ("metadata.version", ["1.0.0"]), ("metadata.timestamp", ["2023-01-01T00:00:00Z"]), ("bar.config.nested", [{"key1": "value1", "key2": "value2"}]), ("bar.config.nested.key1", ["value1"]), ("bar.config.nested.key2", ["value2"]), ("", [json.loads(DEMO_STR)]), # Empty pattern returns full document ("$", [json.loads(DEMO_STR)]), # Root pattern returns full document ], ) def test_extract_json(pattern, expected): assert extract_json(DEMO_STR, pattern) == expected def test_extract_json_invalid_json(): """Test extract_json with invalid JSON""" with pytest.raises(json.JSONDecodeError, match="Invalid JSON"): extract_json("invalid json", "foo") def test_extract_json_invalid_pattern(): """Test extract_json with invalid JSONPath pattern""" with pytest.raises(Exception, match="Invalid JSONPath pattern"): extract_json('{"test": "value"}', "invalid[[[pattern")

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ackness/fetch-jsonpath-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server