The JSON retrocycle function selectively converts certain references only

I have an array of objects with some cyclic references. To handle this, I used JSON.decycle when sending the object via JSON and JSON.retrocycle on the receiving end.

For example:

var refactor_data = JSON.retrocycle(JSON.parse(event.data));

The issue is that some objects in 'refactor_data' have transformed JSONPath references while others do not, and I am unable to determine why.

The objects are quite large, but I can provide a sample if necessary.

EDIT:
Here is a sample of a functional object: http://pastebin.com/1hZDCipn
And here is a sample of a malfunctioning object: http://pastebin.com/PfYCkrGt

EDIT2: It seems like objects with replaced references are actually the originals, and retrocycle may not be making any changes to them. Could this be due to their deep placement within the object structure?

EDIT3: I attempted to execute the eval function that retrocycle should run in FireBug: (It's normal for this to fail)

EDIT4: I inserted a console.log statement within the JSON.retrocycle function, and eval() returns the correct object. However, the returned JSON and the original JSON remain unaltered.

Thank you.

Answer №1

When utilizing the JSON-js cycle.js retrocycle function, it is important to note that paths with array indexes greater than 9 may not be properly retrocycled.

For example, a path like:

$[11]["LegList"][0]["ItenaryList"][0]["Ar"]

will not be retrocycled, while a similar path such as:

$[9]["LegList"][0]["ItenaryList"][0]["Ar"]

will successfully undergo retrocycling. This limitation is due to validation against a regular expression in the cycle.js code.

The regular expression restricts array index values to a single digit only. If a path does not match this pattern, the reference will not be replaced.

To address this issue, consider modifying the cycle.js code by adjusting the regular expression to allow for multiple digits in array indices:

var px = /^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;

This change allows for array indices greater than 9 to be retrocycled successfully. Keep in mind that newer versions of the cycle.js retrocycle function now include this capability.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered: The EVM has reverted the transaction

After successfully deploying this basic smart contract using Remix, I encountered an issue when trying to interact with it through web3.js in my upcoming app. I used the evm version: paris for deployment and everything worked smoothly on Remix IDE. Here i ...

Getting a JWT token from Express to Angular using ngResource: A step-by-step guide

Currently, I am utilizing a jwt token for user registration validation. A unique URL is generated and sent to the user via email, which leads them to the authentication page. On the server side, the token is decoded and I need to transmit this JSON data to ...

Tips for picking a query in Codeigniter and showcasing it in Ionic

I'm unsure if my code for a select query in Codeigniter is correct as I keep receiving this output from my console: View screenshot of my console home.php (Codeigniter - controller) $postdata = file_get_contents("php://input"); if (isset($postdata ...

Array of Geographical Location Data Provided by Google Maps Geocoding

Utilizing a library for Google Geocoding API Wrappers (https://code.google.com/p/gmaps-api-net/) to retrieve or map a full address may sometimes result in inaccuracies. This is often due to missing address types returned by Google, causing discrepancies in ...

Node React authentication

Struggling with implementing authentication in React Router. I am using componentDidMount to check if the user is logged in by calling an endpoint. If not, it should redirect to login, otherwise proceed to the desired component. However, this setup doesn&a ...

I am unable to comprehend the function definition

I have familiarity with different types of JavaScript function declarations such as expression functions and anonymous functions. However, I am unsure about the syntax used in these two specific functions: "manipulateData: function (input)" and "getDataByI ...

When the second history.push is triggered in react-router-dom, it may result in returning an

Hello, I am working with an Antd modal that contains a form. The code snippet for the modal is as follows: <Modal visible={visible} onOk={handleOk} onCancel={handleCancel}> <MyForm onSubmit={handleOpenUrl}> <CustomInput name= ...

Strategies for persisting data in React using local storage to ensure information is retained after page refresh

I am attempting to store searched recipes data in local storage so that when the user refreshes, the data from the last searched recipe will still be available. I have tried saving the recipes data to local storage when a new search request is made and se ...

Connect radio input's value to object's key within AngularJS

Within my controller, I currently have an object structured as follows: $scope.colors = { green: "Green", yellow: "Yellow", red: "Red" }; I am attempting to dynamically generate radio inputs and then link the input value to the corresponding ...

Issue encountered with Google Charts: The object dated 2013-07-25 does not support the 'getTime' method

I'm struggling with creating a chart using the google charts API. One of my columns includes dates, while the other contains numbers. Here is the PHP code that retrieves my data: <?php include 'core/init.php'; $result = mysql_query(&ap ...

React JS - In order to display multiple children, consider utilizing an array rather than individual elements

Currently, I am employing React for my application and utilizing an API located at http://localhost:8080/api/suppliers/supplier/list to fetch data. Upon inspecting the Google Chrome console, this is the format of the data structure I am receiving: 0:{ ...

Despite a valid entry from a list, the controller is receiving null values in MVC 4 with AJAX integration

I am currently developing a "create" form that includes fields for OriginAirportID and DestinationAirportID. Currently, when a user inputs a string of letters into these fields, an AJAX request is triggered to retrieve data in JSON format. This data is th ...

Harness the power of Vue.js by implementing plugin methods in your code

For my first attempt at building a SPA with Vue, I decided to re-use a few functions but encountered some issues. The error message "this.ExperienceToLevel is not a function" kept popping up and it left me puzzled. Furthermore, I'm contemplating if c ...

Changing a dictionary into a pandas DataFrame

Here is the format of my data: {u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}', u'"57e01311817bc367c030b3a8"': u'{"ad_since": 2012, "indoo ...

Ways to activate a stylish pop-up box using an input field (when focus is removed)

While attempting to activate Fancybox upon the user shifting focus away from an input field containing a value greater than 25, everything seems to be in order with the focus out and value checking code. Nevertheless, when Fancybox is triggered, the follow ...

Proper techniques for testing an AngularJS Controller Function

Recently, we integrated jasmine tests into our AngularJS project and I have a query: We are looking to write tests for this controller function: $scope.deleteClick = function () { $scope.processing = true; peopleNotesSrv.deleteNote($scope ...

Display the uploaded images from uploadify on the webpage

I am currently working on a PHP website that utilizes uploadify for users to upload portfolio images. While I have successfully implemented uploadify, I am now exploring the most effective way to display these uploaded images on the webpage without requir ...

Adjustable div height: reduce until reaching a certain point and then begin expanding once more

Incorporating a hero section to display content is my current approach. The design adapts responsively utilizing the padding-bottom percentage strategy, along with an inner container that is absolutely positioned for central alignment of the content. The ...

What is the best way to create an arrow that tracks the browser window, but only goes as far as the end of its designated container

Currently, I am facing a challenge in implementing a scroll down arrow. While this is typically a simple task, it has proven to be a bit more complex this time around. The complexity arises from the fact that my customer desires a homepage with an image of ...

Modify the color of the select element when it is in an open state

If you're new to Material UI, I have a select element that I would like to change the color of. When 'None' is selected, I want the background color of the input field above it to match the 'None' section. Then, when the dropdown m ...