{"id":13147,"date":"2026-09-24T07:35:00","date_gmt":"2026-09-24T05:35:00","guid":{"rendered":"https:\/\/www.lukaswojcik.com\/blog\/?p=13147"},"modified":"2026-11-04T22:47:46","modified_gmt":"2026-11-04T21:47:46","slug":"tutorial-checking-a-json-payload-before-it-goes-into-a-tag","status":"publish","type":"post","link":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/","title":{"rendered":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag"},"content":{"rendered":"<p>A JSON payload can be syntactically valid and still carry the wrong value. Three separate checks help: parsing the original text, checking interoperability risks, and validating the receiving application&#8217;s rules. Formatting alone covers none of these completely.<\/p>\n<p>The examples below run locally. The checker accepts exactly one JSON value, rejects duplicate object members and keeps decimal values without an intermediate binary floating-point conversion. It does not contact a tag manager or analytics service.<\/p>\n<figure class=\"lw-diagram\"><img decoding=\"async\" src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/diagrams\/dia-13147-json-payload-20261024-en.png\" width=\"1120\" height=\"580\" loading=\"lazy\" alt=\"Four stages of JSON checking\"><figcaption>Four stages of JSON checking<\/figcaption><\/figure>\n<h2>The actual JSON text as the starting point<\/h2>\n<p>JSON is a data format, not executable JavaScript. Object names and strings need double quotes. Comments, trailing commas, undefined, NaN and Infinity are outside the JSON grammar. The value categories are object, array, string, number, boolean and null; a document can also consist only of a scalar such as false or 42. Date and identifier conventions belong to the application schema.<\/p>\n<p>An apostrophe inside a double-quoted string is valid. An unescaped line break inside a string is not; the escaped sequence <code>\\n<\/code> represents a newline. Different parsers issue different diagnostics, so a fixed count of \u201cloud\u201d and \u201csilent\u201d errors is not useful.<\/p>\n<p>The original response or file should be retained before formatting. A formatter may refuse malformed JSON and can discard duplicate members or change numeric representation. An error at position zero can come from a byte-order mark, HTML instead of JSON, an empty input or another unexpected first character. It does not diagnose a BOM by itself.<\/p>\n<h2>Duplicate-name checks before information is lost<\/h2>\n<p>RFC 8259 recommends unique names within each object. Receivers handle duplicates differently: common parsers keep the last value, but rejection or preservation of all pairs is also possible. After conversion to an ordinary dictionary, the discarded value may already be unavailable.<\/p>\n<p>For example, <code>{\"a\":{\"x\":1},\"a\":{\"y\":2}}<\/code> repeats the name a even though the paths to the final values, a.x and a.y, differ. A list of repeated streaming leaf paths cannot reliably detect this problem. Conversely, the same name in two separate objects is not a duplicate within one object. The checker uses Python&#8217;s <code>object_pairs_hook<\/code> before building each dictionary, including nested objects and escaped names.<\/p>\n<h2>Identifiers and the receiving schema<\/h2>\n<p>JavaScript Number uses binary floating point. Every integer in the inclusive interval from \u2212(2^53\u22121) to 2^53\u22121 is safe; outside that interval some integers are representable, but not every neighboring integer is distinct. The following Node.js example demonstrates a changed final digit.<\/p>\n<pre><code>const parsed = JSON.parse(&#x27;{&quot;id&quot;:9007199254740993}&#x27;);\nconsole.log(parsed.id); \/\/ 9007199254740992\nconsole.log(Number.isSafeInteger(parsed.id)); \/\/ false\nconst exact = JSON.parse(&#x27;{&quot;id&quot;:&quot;9007199254740993&quot;}&#x27;);\nconsole.log(exact.id); \/\/ &quot;9007199254740993&quot; as a string\n<\/code><\/pre>\n<p>A string preserves this identifier when the receiving API permits a string. An API that requires a number needs its documented representation and limits; changing every identifier to a string unconditionally can make a valid request invalid. A digit-counting regular expression is not a complete precision check: it misses negative or exponent forms and can confuse numeric strings with numbers.<\/p>\n<h2>A local checker with explicit extra rules<\/h2>\n<p>The file uses only Python&#8217;s standard library. Saving it as <code>check_json.py<\/code> allows <code>python3 check_json.py payload.json<\/code>. Exit code 0 means that the local checks passed; exit code 1 means rejection. The file contents are not printed.<\/p>\n<pre><code>import json\nimport sys\nfrom decimal import Decimal, InvalidOperation\nfrom pathlib import Path\n\nMAX_BYTES = 1_048_576  # Local example policy, not a JSON limit.\n\ndef unique_object(pairs):\n    result = {}\n    for key, value in pairs:\n        if key in result:\n            raise ValueError(&quot;duplicate object member&quot;)\n        result[key] = value\n    return result\n\ndef reject_constant(value):\n    raise ValueError(&quot;non-JSON numeric constant&quot;)\n\ndef check(raw):\n    if len(raw) &gt; MAX_BYTES:\n        raise ValueError(&quot;example size limit exceeded&quot;)\n    # Strict UTF-8; this example also rejects a leading BOM.\n    text = raw.decode(&quot;utf-8&quot;)\n    if text.startswith(&quot;\\ufeff&quot;):\n        raise ValueError(&quot;leading BOM rejected by local policy&quot;)\n    value = json.loads(text, object_pairs_hook=unique_object,\n                       parse_float=Decimal, parse_constant=reject_constant)\n    # Reject lone UTF-16 surrogates for interoperable Unicode text.\n    def visit(x):\n        if isinstance(x, str):\n            x.encode(&quot;utf-8&quot;)\n        elif isinstance(x, dict):\n            for key, item in x.items():\n                visit(key)\n                visit(item)\n        elif isinstance(x, list):\n            for item in x:\n                visit(item)\n    visit(value)\n    return value\n\nif __name__ == &quot;__main__&quot;:\n    if len(sys.argv) != 2:\n        raise SystemExit(&quot;Usage: python3 check_json.py payload.json&quot;)\n    try:\n        with Path(sys.argv[1]).open(&quot;rb&quot;) as stream:\n            raw = stream.read(MAX_BYTES + 1)\n        check(raw)\n    except json.JSONDecodeError as exc:\n        print(f&quot;Syntax error: line {exc.lineno}, column {exc.colno}&quot;,\n              file=sys.stderr)\n        raise SystemExit(1)\n    except (OSError, ValueError, UnicodeError, RecursionError,\n            InvalidOperation, OverflowError):\n        print(&quot;Rejected: encoding, duplicate, value or resource policy&quot;,\n              file=sys.stderr)\n        raise SystemExit(1)\n    print(&quot;OK: JSON plus the example&#x27;s interoperability checks&quot;)\n<\/code><\/pre>\n<p>The one-mebibyte limit, rejection of a leading BOM and rejection of lone surrogate characters are explicit interoperability\/resource policies. They are not a claim that every rejected input violates the JSON grammar. The parser also has implementation limits. This example is not a complete defense against hostile input.<\/p>\n<p>Python&#8217;s default decoder accepts NaN and Infinity as extensions; <code>parse_constant<\/code> disables that behavior here. <code>Decimal<\/code> preserves decimal input for checking, while integer input remains a Python integer. Neither choice proves that a later JavaScript consumer or external API can represent the same value.<\/p>\n<h2>Diagnostics from the original evidence<\/h2>\n<p>Python exposes line and column for a syntax error. JavaScript error messages vary by engine and version; extracting an English \u201cposition\u201d phrase is not a portable API. Character offsets, UTF-16 code units and byte offsets must not be mixed. Tabs and line breaks also make a hand-built caret unreliable.<\/p>\n<p>Local inspection around the original location is useful. Production logs should avoid dumping full payloads containing personal data or credentials. A syntax diagnostic locates where parsing failed, which can be after the actual mistake.<\/p>\n<h2>What jq does and does not establish<\/h2>\n<p><code>jq -e .<\/code> is not a pure validity test: valid false and null values produce a nonzero exit status. jq also normally reads a stream of JSON values, so acceptance does not by itself establish exactly one document. Empty input and extensions need explicit treatment. The Python checker above makes the intended policy clear.<\/p>\n<p>Numeric behavior depends on jq version and build options. Literal preservation and arithmetic conversion are separate matters; a blanket guarantee for every build since version 1.7 is incorrect. A pretty-printed copy should not replace the original evidence for precision analysis.<\/p>\n<h2>The actual tag or API contract<\/h2>\n<p>A successful local check does not validate required fields, event names, currency, dates or business rules. The generated payload needs the receiving platform&#8217;s schema and documented diagnostic tools. Responses and processing results must also be observed; an HTTP status alone may not establish correct downstream data.<\/p>\n<p>For JSON-LD, validation applies to the rendered page and the relevant structured-data type. One broken block does not prove that every other block is unreadable. Correct syntax also does not guarantee rich results. For tag templates, import validation and runtime behavior are separate checks; the failure point depends on the actual format and platform.<\/p>\n<div class=\"lw-faq\">\n<h2>Questions and answers<\/h2>\n<h3>How does JSON.parse in the browser handle duplicate names?<\/h3>\n<p>It reports no error and keeps the last value. <code>{\"a\":1,\"a\":2}<\/code> becomes an object with a = 2, and nothing in the result shows that there was a first value. A tag that reads the payload in the browser therefore never sees the duplicate, which is why checking the original text before parsing pays off.<\/p>\n<h3>Which values does JSON.stringify change silently when generating a payload?<\/h3>\n<p>Several, and only one case raises an error. Code that assembles a payload in JavaScript, for example in a custom variable, can run into these cases:<\/p>\n<ul>\n<li><code>NaN<\/code>, <code>Infinity<\/code> and <code>-Infinity<\/code> become <code>null<\/code>. A failed conversion thus arrives as valid JSON.<\/li>\n<li>Properties whose value is <code>undefined<\/code>, a function or a symbol are dropped from objects; in arrays they become <code>null<\/code>. A required field can go missing without any message.<\/li>\n<li>A <code>Date<\/code> object becomes a string in ISO format in UTC. If the receiver expects a different date format or local time, the value does not fit.<\/li>\n<li><code>Map<\/code> and <code>Set<\/code> become empty objects.<\/li>\n<li>A <code>BigInt<\/code> throws a TypeError. That is the only loud case.<\/li>\n<\/ul>\n<p>The checker from the article only catches what remains visible in the text. A missing field or a null in the wrong place only shows up against the receiver\u2019s schema.<\/p>\n<h3>Why does the checker read decimal numbers as Decimal rather than float?<\/h3>\n<p>Because float converts every decimal number to a binary value, and many decimal fractions are only approximated in the process. As a float, the amount 19.99 becomes a value just below it, which usually prints as <code>19.99<\/code> again but differs in calculations; the well-known case is <code>0.1 + 0.2<\/code>, which yields <code>0.30000000000000004<\/code>. From 16 significant digits on, a binary value can no longer reliably reproduce a literal; the identifier 9007199254740993 in the article shows this in JavaScript.<\/p>\n<p>Decimal keeps the literal as written. That allows rules to be checked against the written value, such as at most two decimal places for an amount; <code>Decimal(\"19.990\")<\/code> has three, although it describes the same numeric value. Whether a later receiver has the same precision remains open, as the article points out.<\/p>\n<h3>Can an oversized identifier still be rescued after JSON.parse?<\/h3>\n<p>Not from the parsed object. The number in it has already been rounded to the nearest representable value, 9007199254740993 having become 9007199254740992, and no later conversion knows the original digit. The value only survives if it is read from the original text before parsing or if the source delivers it as a string from the start.<\/p>\n<\/div>\n<h2>Sources<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc8259.html\">RFC 8259: JSON grammar and interoperability<\/a><\/li>\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/json.html\">Python: JSON decoding hooks and limits<\/a><\/li>\n<li><a href=\"https:\/\/jqlang.org\/manual\/\">jq: exit status, input stream and numeric behavior<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Number\/MAX_SAFE_INTEGER\">MDN: safe integers<\/a><\/li>\n<li><a href=\"https:\/\/developers.google.com\/search\/docs\/appearance\/structured-data\/intro-structured-data\">Google: structured data validation<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A local JSON check separates syntax, duplicate names and numeric precision from application rules. A tested Python example handles nested duplicates and valid scalar values without printing the payload.<\/p>\n","protected":false},"author":1,"featured_media":30208,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[91144,91312,91219],"class_list":["post-13147","post","type-post","status-publish","format-standard","hentry","category-tutorials-en-web-development","tag-devops","tag-javascript","tag-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik<\/title>\n<meta name=\"description\" content=\"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik\" \/>\n<meta property=\"og:description\" content=\"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukas Wojcik - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-24T05:35:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-04T21:47:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Lukas Wojcik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lukas Wojcik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/\"},\"author\":{\"name\":\"Lukas Wojcik\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"headline\":\"Tutorial: Checking a JSON Payload Before It Goes Into a Tag\",\"datePublished\":\"2026-09-24T05:35:00+00:00\",\"dateModified\":\"2026-11-04T21:47:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/\"},\"wordCount\":1316,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-13147-13147.png\",\"keywords\":[\"DevOps\",\"JavaScript\",\"Tutorial\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/\",\"name\":\"Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-13147-13147.png\",\"datePublished\":\"2026-09-24T05:35:00+00:00\",\"dateModified\":\"2026-11-04T21:47:46+00:00\",\"description\":\"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-13147-13147.png\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-13147-13147.png\",\"width\":1200,\"height\":630,\"caption\":\"Tutorial: Checking a JSON Payload Before It Goes Into a Tag\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/tutorials-en-web-development\\\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial: Checking a JSON Payload Before It Goes Into a Tag\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\",\"name\":\"Lukas Wojcik - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\",\"name\":\"Lukas Wojcik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"width\":424,\"height\":636,\"caption\":\"Lukas Wojcik\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik","description":"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik","og_description":"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.","og_url":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/","og_site_name":"Lukas Wojcik - Blog","article_published_time":"2026-09-24T05:35:00+00:00","article_modified_time":"2026-11-04T21:47:46+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png","type":"image\/png"}],"author":"Lukas Wojcik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Lukas Wojcik","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#article","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/"},"author":{"name":"Lukas Wojcik","@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"headline":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag","datePublished":"2026-09-24T05:35:00+00:00","dateModified":"2026-11-04T21:47:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/"},"wordCount":1316,"commentCount":0,"publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png","keywords":["DevOps","JavaScript","Tutorial"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/","url":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/","name":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag | Lukas Wojcik","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#primaryimage"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png","datePublished":"2026-09-24T05:35:00+00:00","dateModified":"2026-11-04T21:47:46+00:00","description":"Why a JavaScript object is not JSON, the five errors that raise an exception, and the two that change a value without any warning.","breadcrumb":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#primaryimage","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-13147-13147.png","width":1200,"height":630,"caption":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag"},{"@type":"BreadcrumbList","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/tutorials-en-web-development\/tutorial-checking-a-json-payload-before-it-goes-into-a-tag\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lukaswojcik.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tutorial: Checking a JSON Payload Before It Goes Into a Tag"}]},{"@type":"WebSite","@id":"https:\/\/www.lukaswojcik.com\/blog\/#website","url":"https:\/\/www.lukaswojcik.com\/blog\/","name":"Lukas Wojcik - Blog","description":"","publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lukaswojcik.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9","name":"Lukas Wojcik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","width":424,"height":636,"caption":"Lukas Wojcik"},"logo":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg"},"sameAs":["https:\/\/www.lukaswojcik.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/13147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/comments?post=13147"}],"version-history":[{"count":5,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/13147\/revisions"}],"predecessor-version":[{"id":27035,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/13147\/revisions\/27035"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media\/30208"}],"wp:attachment":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media?parent=13147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/categories?post=13147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/tags?post=13147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}