Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:28:29+00:00 2026-05-24T22:28:29+00:00

I have a array of objects some of whom have cyclic references in them.

  • 0

I have a array of objects some of whom have cyclic references in them. So I used JSON.decycle upon sending the object via JSON and JSON.retrocycle on the other end.

Something like this:

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

The problem is that some of the ojects in ‘refactor_data’ have the JSONPath references transformed while other don’t and I can’t figure out why.

The objects are fairly large but if needed I’ll try to provide a sample.

EDIT:
Here is a sample of an OK object: http://pastebin.com/1hZDCipn
And here is a sample of an broken object: http://pastebin.com/PfYCkrGt

EDIT2:
I think the ones that have the references ‘replaced’ are actually the originals and retrocycle actually doesn’t do anything on any of them. Could this be because they are too ‘deep’ within the object structure ?

EDIT3: I’ve tried to run in FireBug the eval that retrocycle should run: (I think it’s normal for this not to work)

EDIT4: I’ve added a console.log within the JSON.retrocycle function and eval() return the correct object but the returned JSON and original JSON are unaltered.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:28:30+00:00Added an answer on May 24, 2026 at 10:28 pm

    The JSON-js cycle.js retrocycle function does not expect a path to have an array index greater than 9.

    One example path that is not being retrocycled is:

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

    A similar path that does get retrocycled is:

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

    If you look at the cycle.js code, you will see that in order for a path to be retrocycled, it must validate against a regular expression.

    // [...] A PATH is expected to be
    // reasonably short. A PATH is allowed to belong to a very restricted subset of
    // Goessner's JSONPath.
    
    // So,
    // var s = '[{"$ref":"$"}]';
    // return JSON.retrocycle(JSON.parse(s));
    // produces an array containing a single element which is the array itself.
    
    var px =
        /^\$(?:\[(?:\d?|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
    

    In the px regular expression, only one digit array indexes are allowed, not two.
    Since the path does not match the pattern, it will not replace the reference.

    You could try using a local copy of cycle.js and changing the px regular expression to:

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

    Note the difference from the previous regular expression: we are saying that we will now allow one or more digits in array indices. This is accomplished by replacing the single ? character after the first d with a +.

    Edit: Newer versions of the cycle.js retrocycle function now allow array indices that are greater than 9.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bidimensional Object array in Java. Some indices aren´t used, because they
I have some code where I'm returning an array of objects. Here's a simplified
I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I have a mutable array that is retained and storing several objects. At some
I have an array which contains objects some may be same and some are
I have an array of objects and I need them sorted by their title
I have an array of objects (data) data[0].image = image1.jpg; data[0].name = some name;
In a PHP program I have an array of some custom objects, and I
I have an Array of Objects which I want to filter depending on some
I have an array of objects, some of which respond to :description, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.