0

So I have a very big JSON string that represents a multidimensional array with 255 entries, each entry, being an array with 255 other entries, liek this:

0 => array(0, 1, ..., 255),
1 => array(0, 1, ..., 255),

...
255 => array(0, 1, ..., 255),

(the only difference is that the values from the 2nd level are strings made out of 2-3 characters in my case)

Could I retrieve a certain value from this encoded string based on a key, but without actually decoding it to an array?

for example, I may want to get $arr[37][78];

To do this currently I'd have to:

$arr = json_decode($string);
$value = $arr[37][78];

Which I'd like to avoid because the decoded string takes a huge amount of memory as an array...

3
  • Is it really that huge when the items only contain 3 chars? Commented Aug 12, 2012 at 0:36
  • not all of them, some have more. But most of them have 3 Commented Aug 12, 2012 at 0:39
  • It's theoretically possible, but I wouldn't want to go through that exercise. Like pixeline said, regex, substring or manual parsing (ie, find the 37*255th opening bracket, etc. Ugly. Agree with Petra, you are looking at like < 200KB by my quick estimation. Commented Aug 12, 2012 at 0:47

1 Answer 1

1

No, not based on a key. Since at the point that you receive it it's a string, your only option is regex or substr(), using indexes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.