Skip to content

JSONArray bug #100

Description

@armysarge

Found an issue where i would create a JSONArray object then push JSONObjects to it, then ultimately serialize in the end. It would work, but further down the code where i want to again parse a whole new json string using JSONObject.parse, I would get a "A property already exists with the name: " even though there was only one property with that name.

Example code that broke:

	set JSONLDArray = new JSONArray 'SEEMS TO BE THE PROBLEMATIC LINE
	
	set JSONLDBreadcrumbItem = New JSONobject
	JSONLDBreadcrumbItem.add "@type","ListItem"
	JSONLDBreadcrumbItem.add "position",1
	JSONLDBreadcrumbItem.add "name","Home"
	JSONLDBreadcrumbItem.add "item",siteurl
	JSONLDArray.push JSONLDBreadcrumbItem
	set JSONLDBreadcrumbItem = nothing

	set rsBreadcrumb = conn.Execute(SQL)
	if not rsBreadcrumb.EOF then

		BCProductPageID = rsBreadcrumb("ProductPageID")
		BCProductName = rsBreadcrumb("ProductName")
		BCWebmodulenumber = rsBreadcrumb("WebModuleRefID")
		if isNull(BCWebmodulenumber) then BCWebmodulenumber = 0

		BCDepartmentName = rsBreadcrumb("depz")
		BCCategoryName = rsBreadcrumb("catnamez")
		BCTypeName = rsBreadcrumb("typex")
		BCDepartmentID = rsBreadcrumb("ProductDepartmentID")
		BCCategoryID = rsBreadcrumb("ProductCategoryID")
		BCTypeID = rsBreadcrumb("ProductTypeID")

		set JSONLDBreadcrumbItem = New JSONobject
		JSONLDBreadcrumbItem.add "@type","ListItem"
		JSONLDBreadcrumbItem.add "position",2
		JSONLDBreadcrumbItem.add "name",BCDepartmentName
		JSONLDBreadcrumbItem.add "item",pageurl&"?cid="&BCDepartmentID&"&c1="&BCDepartmentName&"&N="&BCWebmodulenumber
		JSONLDArray.push JSONLDBreadcrumbItem
		set JSONLDBreadcrumbItem = nothing
	end if
	rsBreadcrumb.close
	set rsBreadcrumb = nothing

	set JSONLDBreadcrumbList = New JSONobject
	JSONLDBreadcrumbList.add "@context","https://schema.org"
	JSONLDBreadcrumbList.add "@type","BreadcrumbList"
	JSONLDBreadcrumbList.add "itemListElement",JSONLDArray
	response.write("<script type=""application/ld+json"">" & Replace(Replace(JSONLDBreadcrumbList.serialize(),"\/\/","//"),"\/","/") & "</script>")
	set JSONLDBreadcrumbList = nothing

	Set obj = new JSONobject
	obj.Parse("{""test"":[{""hello"":""world""},{""abc"":123}]}") 'IT BREAKS HERE WITH ERROR "A property already exists with the name: test."

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions