0
       public class UserInputFile
        {
            public Action[] actions { get; set; }
        }

        public class Action
        {
            public Action1[] action1 { get; set; }
        }

        public class Action1
        {
            public string[] test { get; set; }
            public string[] status { get; set; }
        }

creating data like below

            UserInputFile inputObject = new UserInputFile()
            Action1 action1 = new Action1();
            action1.test = new[] { "AccptenceTest" };
            action1.status = new[] { "new" };

            Action action = new  Action();
            action.action1 = new[] { action1 };



             Action[] actionarray = new Action[1] { action };
             inputObject = actionarray;

Converting Object to YAML using YAMLDOTNET



        string YamlOutPut = yamlserlizer.Serialize(inputObject);
int id = callMethod(YamlOutPut)

since YamlOutPut doesn't have Dash ( -) before status , i am getting error in callmethod. could you please help me how to add dash (-) in front of status ?

YamlOutPut from above code ( Dash is missing infront of status) :

actions:
- action1:
  - test:
    - AccptenceTest
    status:
    - new

Need below output so that my callmethod works fine . status is missing - infornt of it which is causing the issue . how to add dash to status in Yaml ?

Expected Output :

actions:
- action1:
  - test:
    - AccptenceTest
   - status:
    - new
beginner
  • 39
  • 7
  • 2
    The `-` before `status:`, as you show it, is invalid YAML. The YAML without the `-` is valid and reflects your structure. Why would `callMethod` need invalid YAML as input? You can't use YamlDotNet to create invalid YAML. – flyx Dec 17 '19 at 09:14
  • Why are you serializing your object to JSON, parsing the result as a JObject, serializing it again with ToString(), deserializing it to ExpandoObject, and then finally serializing it to YAML ? You could simply do `yamlserlizer.Serialize(inputObject)`. – Antoine Aubry Dec 17 '19 at 12:20
  • Can you explain what `callMethod` does ? Can you provide its source code ? – Antoine Aubry Dec 17 '19 at 12:21
  • @flyx ,@Antoine Aurby. Thank you for looking into it . i am calling API which is expecting dash infront of status. if i sent dash infront of status, api is working fine .here is the code ```curl -vs -F "upload=@YamlOutPut.yaml" "upload=@Data.xls" http://url:8080/API/apiCall ``` – beginner Dec 17 '19 at 19:33
  • i dont have control on api so tryting to add dash infront of status – beginner Dec 17 '19 at 22:46
  • 1
    If the API expects this input, it's not using YAML (as the input is invalid YAML) and you can't use a YAML library to craft its input. Are you absolutely sure you're showing the expected input as it should be (especially with the indentation of `- status:`)? – flyx Dec 18 '19 at 09:32

0 Answers0