If I had a JSON file that had multiple objects, can the method read through without some form of exception?

  • 1
    \$\begingroup\$ Have you considered trying it? \$\endgroup\$ – Tyyppi_77 Jan 29 '19 at 13:29
  • \$\begingroup\$ As Tyyppi_77 says, this is something you can answer much faster for yourself by just making a multi-object JSON file and trying to parse it. Does the data come through as expected? Or does it throw an Exception? Boom, you have your answer - no internet hearsay required. :) \$\endgroup\$ – DMGregory Jan 29 '19 at 13:40
  • \$\begingroup\$ @DMGregory Alright, sorry about that. \$\endgroup\$ – Kennichi Nitta Jan 29 '19 at 22:01

It looks like the implementation of parse_json calls JSON::parse. JSON::parse looks like a fairly generic JSON parsing routine, but it does expect the top-level of the JSON fed to it to be a single value (since defers, once, to _parse_value).

Thus, it looks like you can provide it JSON containing multiple objects within a top-level array or structure. But if you provide it a string that happens to contain two independent sets of JSON, it will only parse the first one.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.