OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.41k stars 2.39k forks source link

liquid jsonparse documentation example results in error #6497

Closed Flarescape closed 4 years ago

Flarescape commented 4 years ago

OC RC2 13535 (latest dev)

The liquid example from the docs results in the following error, even if I remove the wrong comma: JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.

Update after some research: @jptissot You are using JObject.Parse right now, but if you use the example from the docs, it only works with JArray.Parse, because JObject.Parse is not the a universal parser for json strings.

jptissot commented 4 years ago

Maybe JToken.Parse() would work ? https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JToken_Parse.htm

Flarescape commented 4 years ago

Just tried it and it would work for this example, but I read that JToken is the base type so it's recommended to use JToken.Parse. https://www.newtonsoft.com/json/help/html/ParseJsonAny.htm

jptissot commented 4 years ago

Ok, I think I never tested with using arrays directly, my original example was using an object ;) Submitting a PR

Flarescape commented 4 years ago

I just tried this example: https://docs.orchardcore.net/en/dev/docs/reference/modules/Liquid/#jsonparse 😄

Perfect, thank you. 👍

jptissot commented 4 years ago

Thanks for noticing :)