1
\$\begingroup\$

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

\$\endgroup\$
3
  • 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\$ Jan 29 '19 at 22:01
3
\$\begingroup\$

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.

\$\endgroup\$

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .